Skip to content

Commit

Permalink
Merge pull request #778 from tighten/fix-percent-in-param
Browse files Browse the repository at this point in the history
Fix params sometimes being double-decoded
  • Loading branch information
bakerkretzmar authored Oct 17, 2024
2 parents a8a5984 + 74ce691 commit 5b3b84a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/js/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ export default class Route {

const [location, query] = url.replace(/^\w+:\/\//, '').split('?');

const matches = new RegExp(`^${pattern}/?$`).exec(decodeURI(location));
const matches =
new RegExp(`^${pattern}/?$`).exec(location) ??
new RegExp(`^${pattern}/?$`).exec(decodeURI(location));

if (matches) {
for (const k in matches.groups) {
Expand Down
7 changes: 7 additions & 0 deletions tests/js/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,13 @@ describe('current()', () => {
expect(route().current('statistics')).toBe(true);
});

test('can check the current route with encoded percent sign', () => {
global.window.location.pathname = '/optionalpage/john%25';

expect(route().current()).toBe('pages.optional');
expect(route().current('pages.optional')).toBe(true);
});

test('can ignore routes that don’t allow GET requests', () => {
global.window.location.pathname = '/posts/1';

Expand Down

0 comments on commit 5b3b84a

Please sign in to comment.