Skip to content

Commit

Permalink
Limit slash decoding to last param again
Browse files Browse the repository at this point in the history
  • Loading branch information
bakerkretzmar committed Aug 18, 2023
1 parent 32568e1 commit e26df66
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/js/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ export default class Route {
throw new Error(`Ziggy error: '${segment}' parameter does not match required format '${this.wheres[segment]}' for route '${this.name}'.`)
}

return encodeURIComponent(params[segment] ?? '').replace(/%2F/g, '/');
if (segments[segments.length - 1].name === segment) {
return encodeURIComponent(params[segment] ?? '').replace(/%2F/g, '/');
}
}

return encodeURIComponent(params[segment] ?? '');
Expand Down
2 changes: 1 addition & 1 deletion tests/js/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ describe('route()', () => {
same(route('slashesOtherRegex', ['one/two/three', 'Fun&Games/venues/outdoors']), 'https://ziggy.dev/slashes/one%2Ftwo%2Fthree/Fun%26Games/venues/outdoors');
});

test('skip encoding slashes inside middle parameter when explicitly allowed', () => {
test.skip('skip encoding slashes inside middle parameter when explicitly allowed', () => {
same(route('slashesMiddleParam', ['one/two', 'three/four']), 'https://ziggy.dev/slashes/one/two/three/four');
same(route('slashesMiddleParam', ['one/two', 'Fun&Games/venues']), 'https://ziggy.dev/slashes/one/two/Fun%26Games/venues');
same(route('slashesMiddleParam', ['one/two/three', 'Fun&Games/venues/outdoors']), 'https://ziggy.dev/slashes/one/two/three/Fun%26Games/venues/outdoors');
Expand Down

0 comments on commit e26df66

Please sign in to comment.