Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make slash "not encoding" less restrictive #661

Merged
merged 4 commits into from
Aug 18, 2023
Merged
Changes from 1 commit
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
Next Next commit
Prevent encoding slashes only after wheres matches the param
  • Loading branch information
antoine committed Aug 17, 2023
commit 331d5a4f917cf7d70d56262fd93ff474905b0cc7
12 changes: 6 additions & 6 deletions src/js/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class Route {
const [location, query] = url.replace(/^\w+:\/\//, '').split('?');

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

if (matches) {
for (const k in matches.groups) {
matches.groups[k] = typeof matches.groups[k] === 'string' ? decodeURIComponent(matches.groups[k]) : matches.groups[k];
Expand Down Expand Up @@ -109,12 +109,12 @@ export default class Route {
throw new Error(`Ziggy error: '${segment}' parameter is required for route '${this.name}'.`)
}

if (segments[segments.length - 1].name === segment && this.wheres[segment] === '.*') {
return encodeURIComponent(params[segment] ?? '').replace(/%2F/g, '/');
}
if (this.wheres[segment]) {
if(!new RegExp(`^${optional ? `(${this.wheres[segment]})?` : this.wheres[segment]}$`).test(params[segment] ?? '')) {
throw new Error(`Ziggy error: '${segment}' parameter does not match required format '${this.wheres[segment]}' for route '${this.name}'.`)
}

if (this.wheres[segment] && !new RegExp(`^${optional ? `(${this.wheres[segment]})?` : this.wheres[segment]}$`).test(params[segment] ?? '')) {
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, '/');
}

return encodeURIComponent(params[segment] ?? '');
Expand Down