Skip to content

Commit dd72e10

Browse files
fix($urlMatcherFactory): concat respects strictMode/caseInsensitive
closes #1395 - Changed concat to delegate to $urlMatcherFactoryProvider.compile()
1 parent 9837c09 commit dd72e10

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

src/urlMatcherFactory.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ UrlMatcher.prototype.concat = function (pattern, config) {
180180
// Because order of search parameters is irrelevant, we can add our own search
181181
// parameters to the end of the new pattern. Parse the new pattern by itself
182182
// and then join the bits together, but it's much easier to do this on a string level.
183-
return new UrlMatcher(this.sourcePath + pattern + this.sourceSearch, config);
183+
return new $$UrlMatcherFactoryProvider.compile(this.sourcePath + pattern + this.sourceSearch, config);
184184
};
185185

186186
UrlMatcher.prototype.toString = function () {
@@ -435,6 +435,7 @@ Type.prototype.$subPattern = function() {
435435

436436
Type.prototype.pattern = /.*/;
437437

438+
var $$UrlMatcherFactoryProvider;
438439
/**
439440
* @ngdoc object
440441
* @name ui.router.util.$urlMatcherFactory
@@ -444,6 +445,7 @@ Type.prototype.pattern = /.*/;
444445
* is also available to providers under the name `$urlMatcherFactoryProvider`.
445446
*/
446447
function $UrlMatcherFactory() {
448+
$$UrlMatcherFactoryProvider = this;
447449

448450
var isCaseInsensitive = false, isStrictMode = true;
449451

@@ -546,7 +548,7 @@ function $UrlMatcherFactory() {
546548
*
547549
* @description
548550
* Creates a {@link ui.router.util.type:UrlMatcher `UrlMatcher`} for the specified pattern.
549-
*
551+
*
550552
* @param {string} pattern The URL pattern.
551553
* @param {Object} config The config object hash.
552554
* @returns {UrlMatcher} The UrlMatcher.

test/urlMatcherFactorySpec.js

+26-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
describe("UrlMatcher", function () {
2+
var provider;
3+
beforeEach(function() {
4+
angular.module('ui.router.router.test', function() {}).config(function ($urlMatcherFactoryProvider) {
5+
provider = $urlMatcherFactoryProvider;
6+
});
27

3-
describe("provider", function () {
4-
5-
var provider;
6-
7-
beforeEach(function() {
8-
angular.module('ui.router.router.test', function() {}).config(function ($urlMatcherFactoryProvider) {
9-
provider = $urlMatcherFactoryProvider;
10-
});
11-
12-
module('ui.router.router', 'ui.router.router.test');
8+
module('ui.router.router', 'ui.router.router.test');
139

14-
inject(function($injector) {
15-
$injector.invoke(provider.$get);
16-
});
10+
inject(function($injector) {
11+
$injector.invoke(provider.$get);
1712
});
13+
});
1814

15+
describe("provider", function () {
1916
it("should factory matchers with correct configuration", function () {
2017
provider.caseInsensitive(false);
2118
expect(provider.compile('/hello').exec('/HELLO')).toBeNull();
@@ -165,6 +162,22 @@ describe("UrlMatcher", function () {
165162
var matcher = base.concat('/{repeat:[0-9]+}?to');
166163
expect(matcher).toNotBe(base);
167164
});
165+
166+
it("should respect $urlMatcherFactoryProvider.strictMode", function() {
167+
var m = new UrlMatcher('/');
168+
provider.strictMode(false);
169+
m = m.concat("foo");
170+
expect(m.exec("/foo")).toEqual({});
171+
expect(m.exec("/foo/")).toEqual({})
172+
});
173+
174+
it("should respect $urlMatcherFactoryProvider.caseInsensitive", function() {
175+
var m = new UrlMatcher('/');
176+
provider.caseInsensitive(true);
177+
m = m.concat("foo");
178+
expect(m.exec("/foo")).toEqual({});
179+
expect(m.exec("/FOO")).toEqual({});
180+
});
168181
});
169182
});
170183

0 commit comments

Comments
 (0)