Skip to content

fix($urlMatcherFactory): regex params should respect case-sensitivity #1713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/urlMatcherFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var $$UMFP; // reference to $UrlMatcherFactoryProvider
* of search parameters. Multiple search parameter names are separated by '&'. Search parameters
* do not influence whether or not a URL is matched, but their values are passed through into
* the matched parameters returned by {@link ui.router.util.type:UrlMatcher#methods_exec exec}.
*
*
* Path parameter placeholders can be specified using simple colon/catch-all syntax or curly brace
* syntax, which optionally allows a regular expression for the parameter to be specified:
*
Expand All @@ -21,13 +21,13 @@ var $$UMFP; // reference to $UrlMatcherFactoryProvider
* regexp itself contain curly braces, they must be in matched pairs or escaped with a backslash.
*
* Parameter names may contain only word characters (latin letters, digits, and underscore) and
* must be unique within the pattern (across both path and search parameters). For colon
* must be unique within the pattern (across both path and search parameters). For colon
* placeholders or curly placeholders without an explicit regexp, a path parameter matches any
* number of characters other than '/'. For catch-all placeholders the path parameter matches
* any number of characters.
*
*
* Examples:
*
*
* * `'/hello/'` - Matches only if the path is exactly '/hello/'. There is no special treatment for
* trailing slashes, and patterns have to match the entire path, not just a prefix.
* * `'/user/:id'` - Matches '/user/bob' or '/user/1234!!!' or even '/user/' but not '/user' or
Expand Down Expand Up @@ -60,7 +60,7 @@ var $$UMFP; // reference to $UrlMatcherFactoryProvider
*
* @property {string} sourceSearch The search portion of the source property
*
* @property {string} regex The constructed regex that will be used to match against the url when
* @property {string} regex The constructed regex that will be used to match against the url when
* it is time to determine which url will match.
*
* @returns {Object} New `UrlMatcher` object
Expand Down Expand Up @@ -119,7 +119,7 @@ function UrlMatcher(pattern, config, parentMatcher) {
cfg = config.params[id];
segment = pattern.substring(last, m.index);
regexp = isSearch ? m[4] : m[4] || (m[1] == '*' ? '.*' : null);
type = $$UMFP.type(regexp || "string") || inherit($$UMFP.type("string"), { pattern: new RegExp(regexp) });
type = $$UMFP.type(regexp || "string") || inherit($$UMFP.type("string"), { pattern: new RegExp(regexp, config.caseInsensitive ? 'i' : undefined) });
return {
id: id, regexp: regexp, segment: segment, type: type, cfg: cfg
};
Expand Down Expand Up @@ -275,7 +275,7 @@ UrlMatcher.prototype.exec = function (path, searchParams) {
*
* @description
* Returns the names of all path and search parameters of this pattern in an unspecified order.
*
*
* @returns {Array.<string>} An array of parameter names. Must be treated as read-only. If the
* pattern has no parameters, an empty array is returned.
*/
Expand Down
11 changes: 9 additions & 2 deletions test/urlMatcherFactorySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ describe("UrlMatcher", function () {
expect(m.exec("/FOO")).toEqual({});
});

it("should respect $urlMatcherFactoryProvider.caseInsensitive when validating regex params", function() {
var m = new UrlMatcher('/');
provider.caseInsensitive(true);
m = m.concat("foo/{param:bar}");
expect(m.validates({param:'BAR'})).toEqual(true);
});

it("should generate/match params in the proper order", function() {
var m = new UrlMatcher('/foo?queryparam');
m = m.concat("/bar/:pathparam");
Expand Down Expand Up @@ -423,7 +430,7 @@ describe("urlMatcherFactoryProvider", function () {
});

describe("urlMatcherFactory", function () {

var $umf;

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

it("should correctly format with an optional followed by a required parameter", function() {
var m = new UrlMatcher('/home/:user/gallery/photos/:photo', {
params: {
params: {
user: {value: null, squash: true},
photo: undefined
}
Expand Down