Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const exec = (url, route, matches = {}) => {
if (!m && param == val) continue;
// /foo/* match
if (!m && val && flag == '*') {
matches.rest = '/' + url.slice(i).map(decodeURIComponent).join('/');
matches.rest = '/' + url.slice(i).join('/');
break;
}
// segment mismatch / missing required field:
Expand Down
5 changes: 5 additions & 0 deletions test/node/router-match.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ test('Handles leading/trailing slashes', () => {
});
});

test('Percent-encoded characters in rest are not decoded', () => {
const result = execPath('/nested/child/%25', '/nested/*');
assert.equal(result, { path: '/nested/child/%25', params: {}, query: {}, rest: '/child/%25' });
});

test('should not overwrite existing properties', () => {
const result = execPath('/foo/bar', '/:path/:query', { path: '/custom-path' });
assert.equal(result, {
Expand Down
29 changes: 29 additions & 0 deletions test/router.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,35 @@ describe('Router', () => {
expect(params).to.deep.include({ id: 'bar' });
});

it('should not double-decode percent-encoded characters in nested routes', async () => {
let route;
const Inner = () => (
<Router>
<Route
path="/child/:id"
component={() => {
route = useRoute();
return null;
}}
/>
</Router>
);

render(
<LocationProvider>
<Router>
<Route path="/nested/*" component={Inner} />
</Router>
<a href="/nested/child/%25"></a>
</LocationProvider>,
scratch
);

scratch.querySelector('a[href="/nested/child/%25"]').click();
await sleep(1);
expect(route).to.deep.include({ params: { id: '%' } });
});

it('should replace the current URL', async () => {
const pushState = sinon.spy(history, 'pushState');
const replaceState = sinon.spy(history, 'replaceState');
Expand Down
Loading