-
Notifications
You must be signed in to change notification settings - Fork 28.4k
Don't throw errors when we give "asPathToSearchParams()" an invalid path with multiple leading slashes #70144
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
base: canary
Are you sure you want to change the base?
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 |
26b30aa
to
6691621
Compare
6691621
to
6a78b62
Compare
Hello, maintainers! It's been about 4 weeks since I last commented. Sorry for the inconvenience 🙏 |
Failing test suitesCommit: 6a78b62
Expand output● Undefined default export › should error when page component export is not valid
Read more about building and testing Next.js in contributing.md.
Expand output● 404 handling › custom _error › production mode › next export › should handle double slashes correctly
● 404 handling › custom _error › production mode › next export › should handle double slashes correctly with query
● 404 handling › custom _error › production mode › next export › should handle double slashes correctly with hash
● 404 handling › custom _error › production mode › next export › should handle backslashes correctly
● 404 handling › custom _error › production mode › next export › should handle mixed backslashes/forward slashes correctly
● 404 handling › pages/404 › production mode › production mode › next export › should handle double slashes correctly
● 404 handling › pages/404 › production mode › production mode › next export › should handle double slashes correctly with query
● 404 handling › pages/404 › production mode › production mode › next export › should handle double slashes correctly with hash
● 404 handling › pages/404 › production mode › production mode › next export › should handle backslashes correctly
● 404 handling › pages/404 › production mode › production mode › next export › should handle mixed backslashes/forward slashes correctly
Read more about building and testing Next.js in contributing.md. |
@ijjk I didn't expect this PR at this point to have such an impact on other features (testing). I apologize for taking up your valuable time. |
6a78b62
to
14f9732
Compare
965ef85
to
1877dba
Compare
@ijjk (Cc: @huozhi) After that, I reviewed the patch and changed the patch so that the existing test set would not fail and the new test set would pass. I apologize for the inconvenience, but I would appreciate it if you could review the PR again 🙏 The following screenshots are the results of the retest:
|
2b25d12
to
1632a03
Compare
1632a03
to
70b12cc
Compare
70b12cc
to
bba9faa
Compare
Hello. pnpm test-start test I looked at the testing section in the documentation, but there was no command written to run exhaustive tests equivalent to CI. I apologize for the inconvenience, but would it be possible for you to give me a list of commands (I believe there are probably multiple) to run the same tests in the local environment as those running in CI...? |
Hello, can anyone answer the above question...? |
bba9faa
to
08c8a7e
Compare
Please Help me. Is it possible to read a comment mentioned above and receive a reply...? |
08c8a7e
to
7211b4a
Compare
7211b4a
to
1681620
Compare
…root-index-page-have-multiple-slash
…root-index-page-have-multiple-slash
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
URL
constructor inasPathToSearchParams()
utility function can't parse URL root-relative paths that have two or more extra slashes, throw an error.The root cause is that the path string returned by
getURL()
can have two or more slashes at the beginning.How?
Add processing to the
asPathToSearchParams()
utility function to replace two or more leading slashes with one slash.Note
HTTP
web browser environments, only inHTTPS
web browser environmentsCloses NEXT-
Fixes #