Skip to content

Commit 1e10519

Browse files
fix($urlMatcherFactory): regex params should respect case-sensitivity
Fixes #1671
1 parent 6cbee63 commit 1e10519

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/urlMatcherFactory.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var $$UMFP; // reference to $UrlMatcherFactoryProvider
1010
* of search parameters. Multiple search parameter names are separated by '&'. Search parameters
1111
* do not influence whether or not a URL is matched, but their values are passed through into
1212
* the matched parameters returned by {@link ui.router.util.type:UrlMatcher#methods_exec exec}.
13-
*
13+
*
1414
* Path parameter placeholders can be specified using simple colon/catch-all syntax or curly brace
1515
* syntax, which optionally allows a regular expression for the parameter to be specified:
1616
*
@@ -21,13 +21,13 @@ var $$UMFP; // reference to $UrlMatcherFactoryProvider
2121
* regexp itself contain curly braces, they must be in matched pairs or escaped with a backslash.
2222
*
2323
* Parameter names may contain only word characters (latin letters, digits, and underscore) and
24-
* must be unique within the pattern (across both path and search parameters). For colon
24+
* must be unique within the pattern (across both path and search parameters). For colon
2525
* placeholders or curly placeholders without an explicit regexp, a path parameter matches any
2626
* number of characters other than '/'. For catch-all placeholders the path parameter matches
2727
* any number of characters.
28-
*
28+
*
2929
* Examples:
30-
*
30+
*
3131
* * `'/hello/'` - Matches only if the path is exactly '/hello/'. There is no special treatment for
3232
* trailing slashes, and patterns have to match the entire path, not just a prefix.
3333
* * `'/user/:id'` - Matches '/user/bob' or '/user/1234!!!' or even '/user/' but not '/user' or
@@ -60,7 +60,7 @@ var $$UMFP; // reference to $UrlMatcherFactoryProvider
6060
*
6161
* @property {string} sourceSearch The search portion of the source property
6262
*
63-
* @property {string} regex The constructed regex that will be used to match against the url when
63+
* @property {string} regex The constructed regex that will be used to match against the url when
6464
* it is time to determine which url will match.
6565
*
6666
* @returns {Object} New `UrlMatcher` object
@@ -119,7 +119,7 @@ function UrlMatcher(pattern, config, parentMatcher) {
119119
cfg = config.params[id];
120120
segment = pattern.substring(last, m.index);
121121
regexp = isSearch ? m[4] : m[4] || (m[1] == '*' ? '.*' : null);
122-
type = $$UMFP.type(regexp || "string") || inherit($$UMFP.type("string"), { pattern: new RegExp(regexp) });
122+
type = $$UMFP.type(regexp || "string") || inherit($$UMFP.type("string"), { pattern: new RegExp(regexp, config.caseInsensitive ? 'i' : undefined) });
123123
return {
124124
id: id, regexp: regexp, segment: segment, type: type, cfg: cfg
125125
};
@@ -275,7 +275,7 @@ UrlMatcher.prototype.exec = function (path, searchParams) {
275275
*
276276
* @description
277277
* Returns the names of all path and search parameters of this pattern in an unspecified order.
278-
*
278+
*
279279
* @returns {Array.<string>} An array of parameter names. Must be treated as read-only. If the
280280
* pattern has no parameters, an empty array is returned.
281281
*/

test/urlMatcherFactorySpec.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ describe("UrlMatcher", function () {
185185
expect(m.exec("/FOO")).toEqual({});
186186
});
187187

188+
it("should respect $urlMatcherFactoryProvider.caseInsensitive when validating regex params", function() {
189+
var m = new UrlMatcher('/');
190+
provider.caseInsensitive(true);
191+
m = m.concat("foo/{param:bar}");
192+
expect(m.validates({param:'BAR'})).toEqual(true);
193+
});
194+
188195
it("should generate/match params in the proper order", function() {
189196
var m = new UrlMatcher('/foo?queryparam');
190197
m = m.concat("/bar/:pathparam");
@@ -423,7 +430,7 @@ describe("urlMatcherFactoryProvider", function () {
423430
});
424431

425432
describe("urlMatcherFactory", function () {
426-
433+
427434
var $umf;
428435

429436
beforeEach(module('ui.router.util'));
@@ -626,7 +633,7 @@ describe("urlMatcherFactory", function () {
626633

627634
it("should correctly format with an optional followed by a required parameter", function() {
628635
var m = new UrlMatcher('/home/:user/gallery/photos/:photo', {
629-
params: {
636+
params: {
630637
user: {value: null, squash: true},
631638
photo: undefined
632639
}

0 commit comments

Comments
 (0)