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

lib: fix regular expression to detect / and \ #40325

Closed
wants to merge 1 commit into from
Closed

lib: fix regular expression to detect / and \ #40325

wants to merge 1 commit into from

Conversation

fasttime
Copy link
Contributor

@fasttime fasttime commented Oct 5, 2021

Allow importing from file URLs with encoded commas. Forbid encoded backslashes. Fixes #40305.

@nodejs-github-bot nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. labels Oct 5, 2021
@fasttime fasttime marked this pull request as ready for review October 5, 2021 05:43
@targos
Copy link
Member

targos commented Oct 5, 2021

@nodejs/modules

@targos targos added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 5, 2021
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 5, 2021
@nodejs-github-bot
Copy link
Collaborator

Copy link
Contributor

@guybedford guybedford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks, and apologies for the slip!

@nodejs-github-bot
Copy link
Collaborator

@bmeck
Copy link
Member

bmeck commented Oct 5, 2021

Since , is significant for data: we should add a test for that as well even if this codepath doesn't cover data: normally I could foresee a refactor accidentally mixing the 2.

@guybedford
Copy link
Contributor

@bmeck this code path does apply to data URLs, in that data URLs that contain a percent encoded comma will no longer throw, even if that percent encoding is in the body of the data URL. On the other hand, percent encoded / and \\ in any position of a data URL, including the body, will always throw. One option here could be to separately special case data URLs in opting out of these validations for the body of the data URL. I think that should be a separate PR though.

@bmeck
Copy link
Member

bmeck commented Oct 5, 2021

@guybedford my main concern is how:

import(`data:text/javascript;x="${encodeURIComponent(',')}",export default 123`);

is interpreted and ensuring it works, otherwise we could just leave the , in the regexp in this PR rather than removing it if we just want to fix the slashes. I'd prefer we have a test for the data: impact if we change its behavior.

@guybedford
Copy link
Contributor

@bmeck I believe right now your example would fail across all versions, where this PR fixes that.

@guybedford
Copy link
Contributor

Ah, I see data: URLs have an early exit higher up in the resolver so don't hit this path. We should codify that into the spec as well, will post a PR.

@guybedford
Copy link
Contributor

@bmeck since data URLs definitely never hit this path at all, I don't think there's any test coverage to apply here, are you ok with landing as is to get this fix in? I am working on a PR to clarify the data URL distinction in the spec as well as some other encoding cases.

@bmeck
Copy link
Member

bmeck commented Oct 5, 2021

@guybedford yea that is fine, though also note that Blob is up and coming

@nodejs-github-bot
Copy link
Collaborator

aduh95 pushed a commit to aduh95/node that referenced this pull request Oct 22, 2021
PR-URL: nodejs#40325
Fixes: nodejs#40305
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
aduh95 pushed a commit to aduh95/node that referenced this pull request Oct 22, 2021
PR-URL: nodejs#40325
Fixes: nodejs#40305
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
targos pushed a commit that referenced this pull request Oct 23, 2021
Fixes #40305

PR-URL: #40325
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
@targos targos mentioned this pull request Nov 8, 2021
BethGriggs pushed a commit that referenced this pull request Nov 23, 2021
Fixes #40305

PR-URL: #40325
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
@BethGriggs BethGriggs mentioned this pull request Nov 26, 2021
1 task
richardlau pushed a commit that referenced this pull request Nov 26, 2021
PR-URL: #40325
Backport-PR-URL: #40564
Fixes: #40305
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
richardlau pushed a commit that referenced this pull request Nov 26, 2021
PR-URL: #40325
Backport-PR-URL: #40564
Fixes: #40305
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
@richardlau richardlau mentioned this pull request Nov 26, 2021
BethGriggs added a commit that referenced this pull request Nov 30, 2021
Notable changes:

- **deps**: upgrade npm to 8.1.2 (npm team)
  [#40643](#40643)
- **deps**: update c-ares to 1.18.1 (Richard Lau)
  [#40660](#40660)
- **doc**: add VoltrexMaster to collaborators (voltrexmaster)
  [#40566](#40566)
- **lib**: fix regular expression to detect \`/\` and \`\\\`
  (Francesco Trotta) [#40325](#40325)

PR-URL: #40974
BethGriggs added a commit that referenced this pull request Dec 1, 2021
Notable changes:

- **deps**: upgrade npm to 8.1.2 (npm team)
  [#40643](#40643)
- **deps**: update c-ares to 1.18.1 (Richard Lau)
  [#40660](#40660)
- **doc**: add VoltrexMaster to collaborators (voltrexmaster)
  [#40566](#40566)
- **lib**: fix regular expression to detect \`/\` and \`\\\`
  (Francesco Trotta) [#40325](#40325)

PR-URL: #40974
BethGriggs added a commit that referenced this pull request Dec 1, 2021
Notable changes:

- **deps**: upgrade npm to 8.1.2 (npm team)
  [#40643](#40643)
- **deps**: update c-ares to 1.18.1 (Richard Lau)
  [#40660](#40660)
- **doc**: add VoltrexMaster to collaborators (voltrexmaster)
  [#40566](#40566)
- **lib**: fix regular expression to detect \`/\` and \`\\\`
  (Francesco Trotta) [#40325](#40325)

PR-URL: #40974
richardlau pushed a commit that referenced this pull request Dec 14, 2021
PR-URL: #40325
Backport-PR-URL: #40565
Fixes: #40305
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
@richardlau richardlau mentioned this pull request Dec 15, 2021
Linkgoron pushed a commit to Linkgoron/node that referenced this pull request Jan 31, 2022
Notable changes:

- **deps**: upgrade npm to 8.1.2 (npm team)
  [nodejs#40643](nodejs#40643)
- **deps**: update c-ares to 1.18.1 (Richard Lau)
  [nodejs#40660](nodejs#40660)
- **doc**: add VoltrexMaster to collaborators (voltrexmaster)
  [nodejs#40566](nodejs#40566)
- **lib**: fix regular expression to detect \`/\` and \`\\\`
  (Francesco Trotta) [nodejs#40325](nodejs#40325)

PR-URL: nodejs#40974
abhishekumar-tyagi pushed a commit to abhishekumar-tyagi/node that referenced this pull request May 5, 2024
PR-URL: nodejs/node#40325
Fixes: nodejs/node#40305
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error importing ES module with an encoded comma in the URL
10 participants