From 1e10519f3be6bbf0cefdcce623cd2ade06e649e5 Mon Sep 17 00:00:00 2001 From: Mohammad Younes Date: Wed, 28 Jan 2015 17:25:50 +0200 Subject: [PATCH] fix($urlMatcherFactory): regex params should respect case-sensitivity Fixes #1671 --- src/urlMatcherFactory.js | 14 +++++++------- test/urlMatcherFactorySpec.js | 11 +++++++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/urlMatcherFactory.js b/src/urlMatcherFactory.js index 26ba48b2b..e3d5eeea8 100644 --- a/src/urlMatcherFactory.js +++ b/src/urlMatcherFactory.js @@ -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: * @@ -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 @@ -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 @@ -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 }; @@ -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.} An array of parameter names. Must be treated as read-only. If the * pattern has no parameters, an empty array is returned. */ diff --git a/test/urlMatcherFactorySpec.js b/test/urlMatcherFactorySpec.js index 80950bbb7..26085ee3e 100755 --- a/test/urlMatcherFactorySpec.js +++ b/test/urlMatcherFactorySpec.js @@ -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"); @@ -423,7 +430,7 @@ describe("urlMatcherFactoryProvider", function () { }); describe("urlMatcherFactory", function () { - + var $umf; beforeEach(module('ui.router.util')); @@ -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 }