-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
Fix invalid pathname slashes in "getURL()" utility #70144
base: canary
Are you sure you want to change the base?
Fix invalid pathname slashes in "getURL()" utility #70144
Conversation
a559e15
to
f807db6
Compare
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
This comment was marked as resolved.
This comment was marked as resolved.
f807db6
to
b211556
Compare
If you have more trailing slashes, even standard util will treat them as part of pathname, sounds correct it was thrown as invalid URL?
|
@huozhi Yes, but it doesn't happen in your example... It occurs with the following pattern (this is the code pattern used within new URL(asPath, 'http://n').searchParams The following error should be thrown:
Screenshot: ![]()
|
Initially, I thought that changing new URL(asPath, 'https://n.com').searchParams to new URL(`https://n.com${asPath}`).searchParams would complete the fix. However, when I investigated deeper, I started to think that the fundamental solution might not be solved unless I changed The reason is that the return value of
By fixing the core part, we can avoid problems that may occur in other code that uses the result of |
80de3fd
to
23fc909
Compare
The test seem cannot demostrate the issue you describe, if I manually run in https mode and just visit the page, it looks working correctly 🤔 |
This comment was marked as resolved.
This comment was marked as resolved.
a2879fd
to
7a8c3ee
Compare
Oh, after splitting the test file into If you pnpm build && pnpm test-start test/e2e/invalid-url-slash I'm very sorry. |
1ea30c7
to
ed53e03
Compare
Tests are passed regardless we have the changes |
ed53e03
to
e5a015e
Compare
@huozhi I also confirmed that the e2e test did not fail using the old code. Then I remembered that the case I encountered was a When I rewrote the e2e test using After applying the patch to Thank you for making me realize that. I have pushed the latest code, so please test it yourself 🙏 |
7c48f52
to
0547468
Compare
0547468
to
8f14e57
Compare
For Contributors
Improving Documentation
pnpm prettier-fix
to fix formatting issues before opening the PR.Adding or Updating Examples
pnpm build && pnpm lint
. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.mdFixing a bug
Related issues linked usingfixes #number
For Maintainers
What?
If you access a root page that has two or more extra slashes at the end, such as https://foo.com//, errors throw in the
URL
constructor and Next.js will stop rendering.Why?
Because
getURL()
utility function in/packages/next/src/shared/lib/utils.ts
does not remove two or more extra slashes.How?
Add processing to the
getURL()
utility function to replace two or more leading slashes with one slash.Note
HTTP
web browser environments, only inHTTPS
web browser environmentsCloses NEXT-
Fixes #