From c1493b58c27197505f3102ef9d1b9918cc7bc8ed Mon Sep 17 00:00:00 2001 From: Randy Reddig Date: Wed, 3 Sep 2014 12:27:03 -0700 Subject: [PATCH] [changed] #259 support dots in named params --- modules/utils/Path.js | 2 +- specs/Path.spec.js | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/modules/utils/Path.js b/modules/utils/Path.js index 5e2044dc2a..e212288ef5 100644 --- a/modules/utils/Path.js +++ b/modules/utils/Path.js @@ -25,7 +25,7 @@ function compilePattern(pattern) { var source = pattern.replace(paramMatcher, function (match, paramName) { if (paramName) { paramNames.push(paramName); - return '([^./?#]+)'; + return '([^/?#]+)'; } else if (match === '*') { paramNames.push('splat'); return '(.*?)'; diff --git a/specs/Path.spec.js b/specs/Path.spec.js index 01843687ec..bacbf07a70 100644 --- a/specs/Path.spec.js +++ b/specs/Path.spec.js @@ -126,6 +126,24 @@ describe('Path.extractParams', function () { }); }); }); + + describe('when a param has dots', function () { + var pattern = '/:query/with/:domain'; + + describe('and the path matches', function () { + it('returns an object with the params', function () { + expect(Path.extractParams(pattern, '/foo/with/foo.app')).toEqual({ query: 'foo', domain: 'foo.app' }); + expect(Path.extractParams(pattern, '/foo.ap/with/foo')).toEqual({ query: 'foo.ap', domain: 'foo' }); + expect(Path.extractParams(pattern, '/foo.ap/with/foo.app')).toEqual({ query: 'foo.ap', domain: 'foo.app' }); + }); + }); + + describe('and the path does not match', function () { + it('returns null', function () { + expect(Path.extractParams(pattern, '/foo.ap')).toBe(null); + }); + }); + }); }); describe('Path.injectParams', function () { @@ -169,6 +187,12 @@ describe('Path.injectParams', function () { expect(Path.injectParams(pattern, { id: 'the/id' })).toEqual('comments/the/id/edit'); }); }); + + describe('and some params contain dots', function () { + it('returns the correct path', function () { + expect(Path.injectParams(pattern, { id: 'alt.black.helicopter' })).toEqual('comments/alt.black.helicopter/edit'); + }); + }); }); describe('when a pattern has multiple splats', function () {