Skip to content

Commit c1493b5

Browse files
committed
[changed] #259 support dots in named params
1 parent d38ebf3 commit c1493b5

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

modules/utils/Path.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function compilePattern(pattern) {
2525
var source = pattern.replace(paramMatcher, function (match, paramName) {
2626
if (paramName) {
2727
paramNames.push(paramName);
28-
return '([^./?#]+)';
28+
return '([^/?#]+)';
2929
} else if (match === '*') {
3030
paramNames.push('splat');
3131
return '(.*?)';

specs/Path.spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ describe('Path.extractParams', function () {
126126
});
127127
});
128128
});
129+
130+
describe('when a param has dots', function () {
131+
var pattern = '/:query/with/:domain';
132+
133+
describe('and the path matches', function () {
134+
it('returns an object with the params', function () {
135+
expect(Path.extractParams(pattern, '/foo/with/foo.app')).toEqual({ query: 'foo', domain: 'foo.app' });
136+
expect(Path.extractParams(pattern, '/foo.ap/with/foo')).toEqual({ query: 'foo.ap', domain: 'foo' });
137+
expect(Path.extractParams(pattern, '/foo.ap/with/foo.app')).toEqual({ query: 'foo.ap', domain: 'foo.app' });
138+
});
139+
});
140+
141+
describe('and the path does not match', function () {
142+
it('returns null', function () {
143+
expect(Path.extractParams(pattern, '/foo.ap')).toBe(null);
144+
});
145+
});
146+
});
129147
});
130148

131149
describe('Path.injectParams', function () {
@@ -169,6 +187,12 @@ describe('Path.injectParams', function () {
169187
expect(Path.injectParams(pattern, { id: 'the/id' })).toEqual('comments/the/id/edit');
170188
});
171189
});
190+
191+
describe('and some params contain dots', function () {
192+
it('returns the correct path', function () {
193+
expect(Path.injectParams(pattern, { id: 'alt.black.helicopter' })).toEqual('comments/alt.black.helicopter/edit');
194+
});
195+
});
172196
});
173197

174198
describe('when a pattern has multiple splats', function () {

0 commit comments

Comments
 (0)