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

Encode URIs during server rendering of <a href>/<form action> to avoi… #10769

Merged
merged 7 commits into from Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -118,7 +118,7 @@
"none": "16.3 kB"
},
"packages/react-router-dom/dist/react-router-dom.production.min.js": {
"none": "13.1 kB"
"none": "13.0 kB"
},
"packages/react-router-dom/dist/umd/react-router-dom.production.min.js": {
"none": "19.1 kB"
Expand Down
6 changes: 2 additions & 4 deletions packages/react-router-dom/index.tsx
Expand Up @@ -1508,11 +1508,9 @@ export { usePrompt as unstable_usePrompt };
function safelyEncodeSsrHref(to: To, href: string): string {
let path = typeof to === "string" ? parsePath(to).pathname : to.pathname;
// Only touch the href for auto-generated paths
if (path === null || path === "" || path === ".") {
if (!path || path === ".") {
try {
let encoded = ABSOLUTE_URL_REGEX.test(href)
? new URL(href)
: new URL(href, "http://localhost");
brophdawg11 marked this conversation as resolved.
Show resolved Hide resolved
let encoded = new URL(href, "http://localhost");
return encoded.pathname + encoded.search;
} catch (e) {
// no-op - don't change href if we aren't sure it needs encoding
brophdawg11 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down