Skip to content

Commit

Permalink
[changed] remix-run#259 support dots in named params
Browse files Browse the repository at this point in the history
  • Loading branch information
ydnar committed Sep 3, 2014
1 parent d38ebf3 commit c1493b5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/utils/Path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 '(.*?)';
Expand Down
24 changes: 24 additions & 0 deletions specs/Path.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit c1493b5

Please sign in to comment.