Skip to content

Commit

Permalink
[fixed] Double slash in href when parent route has optional trailing …
Browse files Browse the repository at this point in the history
…slash

When a parent route of a child route has an optional trailing slash, the
generated path for the child route will have two slashes in a row. Fix
the trailing slash matcher pattern to account for this case.

This bug occurs when calling `Path.injectParams(pattern, params)` to
generate a path. The `pattern` for the path of a child route whose
parent has an optional trailing slash looks something like
`parent/?/child`. If we just replace `/?` with `/` we end up with
`parent//child`, so we need to replace `/?/` with `/`.

This fixes issue remix-run#768.
  • Loading branch information
kentor committed Feb 5, 2015
1 parent e43293d commit 5bcf653
Show file tree
Hide file tree
Showing 2 changed files with 7 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 @@ -4,7 +4,7 @@ var qs = require('qs');

var paramCompileMatcher = /:([a-zA-Z_$][a-zA-Z0-9_$]*)|[*.()\[\]\\+|{}^$]/g;
var paramInjectMatcher = /:([a-zA-Z_$][a-zA-Z0-9_$?]*[?]?)|[*]/g;
var paramInjectTrailingSlashMatcher = /\/\/\?|\/\?/g;
var paramInjectTrailingSlashMatcher = /\/\/\?|\/\?\/|\/\?/g;
var queryMatcher = /\?(.+)/;

var _compiledPatterns = {};
Expand Down
6 changes: 6 additions & 0 deletions modules/utils/__tests__/Path-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ describe('Path.injectParams', function () {
expect(Path.injectParams('/foo.bar.baz')).toEqual('/foo.bar.baz');
});
});

describe('when a pattern has optional slashes', function () {
it('returns the correct path', function () {
expect(Path.injectParams('/foo/?/bar/?/baz/?')).toEqual('/foo/bar/baz/');
});
});
});

describe('Path.extractQuery', function () {
Expand Down

0 comments on commit 5bcf653

Please sign in to comment.