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 MIME overmatch in data URLs #49104

Merged
merged 1 commit into from
Aug 13, 2023
Merged

Conversation

andremralves
Copy link
Contributor

This commit adds the delimiters ^ and $ to the regex that matches the MIME types for "data:URLs".
Fixes: #48957

I also added a new test case that expects an ERR_UNKNOWN_MODULE_FORMAT message for MIME types like this: data:WRONGtext/javascriptFORMAT.

This is my first time contributing to node. Let me know if I did everything right 😄.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/modules

@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 Aug 11, 2023
Copy link
Member

@GeoffreyBooth GeoffreyBooth left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! Looks good, just some questions.

@@ -26,7 +26,7 @@ if (experimentalWasmModules) {
function mimeToFormat(mime) {
if (
RegExpPrototypeExec(
/\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i,
/^\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?$/i,
Copy link
Member

Choose a reason for hiding this comment

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

Could there be any other extra “query params,” so to speak, besides charset=utf-8? If so, then we can’t add the $.

This is another issue, but is utf-8 / utf8 the only permitted charset?

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/^\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?$/i,
/^\s*(text|application)\/javascript\s*(;|$)/i,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could there be any other extra “query params,” so to speak, besides charset=utf-8? If so, then we can’t add the $.

I read the MDN article about "Common MIME types" and found a link to the RFC of text/javascript MIME type. They don't mention any other param other than the charset parameter and say that it's optional.

Also, I found out that the first implementation of this code was only matching text/javascript and then someone refactored it to inclued the support for the optional charset parameter.

This is another issue, but is utf-8 / utf8 the only permitted charset?

According to that RFC: "Module goal sources MUST always be processed as UTF-8.", so I think we should be good using just utf-8.

Thanks for the feedback 🚀

@aduh95
Copy link
Contributor

aduh95 commented Aug 11, 2023

This is another issue, but is utf-8 / utf8 the only permitted charset?

I'd say it's not related to this PR, but defaultLoad is ignoring all the params (including charset) except for base64.

@aduh95
Copy link
Contributor

aduh95 commented Aug 11, 2023

Can you fix the test failure please?

@andremralves
Copy link
Contributor Author

Can you fix the test failure please?

Oh, I know what happened. I fixed the linting and the error message ended up being wrong. I will fix.

@andremralves
Copy link
Contributor Author

andremralves commented Aug 11, 2023

@aduh95 I fixed the test failure.

@andremralves
Copy link
Contributor Author

I believe the failure now is not related to this PR. There are other PRs with the same failure.

This commit adds the delimiters ^ and $ to the regex that matches the
MIME types for "data:URLs".
Fixes: nodejs#48957
@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Aug 13, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 13, 2023
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 13, 2023
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Aug 13, 2023
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/49104
✔  Done loading data for nodejs/node/pull/49104
----------------------------------- PR info ------------------------------------
Title      lib: fix MIME overmatch in data URLs (#49104)
   ⚠  Could not retrieve the email or name of the PR author's from user's GitHub profile!
Branch     andremralves:fix-mime -> nodejs:main
Labels     esm, author ready, needs-ci
Commits    1
 - lib: fix MIME overmatch in data URLs
Committers 1
 - Antoine du Hamel 
PR-URL: https://github.com/nodejs/node/pull/49104
Fixes: https://github.com/nodejs/node/issues/48957
Reviewed-By: Geoffrey Booth 
Reviewed-By: Antoine du Hamel 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/49104
Fixes: https://github.com/nodejs/node/issues/48957
Reviewed-By: Geoffrey Booth 
Reviewed-By: Antoine du Hamel 
--------------------------------------------------------------------------------
   ℹ  This PR was created on Fri, 11 Aug 2023 05:08:02 GMT
   ✔  Approvals: 2
   ✔  - Geoffrey Booth (@GeoffreyBooth) (TSC): https://github.com/nodejs/node/pull/49104#pullrequestreview-1573705440
   ✔  - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/49104#pullrequestreview-1575747202
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2023-08-13T17:48:39Z: https://ci.nodejs.org/job/node-test-pull-request/53284/
- Querying data for job/node-test-pull-request/53284/
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  No git cherry-pick in progress
   ✔  No git am in progress
   ✔  No git rebase in progress
--------------------------------------------------------------------------------
- Bringing origin/main up to date...
From https://github.com/nodejs/node
 * branch                  main       -> FETCH_HEAD
✔  origin/main is now up-to-date
- Downloading patch for 49104
From https://github.com/nodejs/node
 * branch                  refs/pull/49104/merge -> FETCH_HEAD
✔  Fetched commits as b5da2f4dad72..00dbd9454ae8
--------------------------------------------------------------------------------
[main a344cdb5e6] lib: fix MIME overmatch in data URLs
 Author: Andre Alves 
 Date: Fri Aug 11 01:47:22 2023 -0300
 2 files changed, 4 insertions(+), 1 deletion(-)
   ✔  Patches applied
--------------------------------------------------------------------------------
   ✘  Git found no trailers in the original commit message, but 'Fixes: https://github.com/nodejs/node/issues/48957' is present and should be a trailer.
https://github.com/nodejs/node/actions/runs/5849556424

@aduh95 aduh95 merged commit 7139198 into nodejs:main Aug 13, 2023
@aduh95
Copy link
Contributor

aduh95 commented Aug 13, 2023

Landed in 7139198, thanks for the contribution 🎉

Ceres6 pushed a commit to Ceres6/node that referenced this pull request Aug 14, 2023
This commit adds the delimiters ^ and $ to the regex that matches the
MIME types for `data:` URLs.

PR-URL: nodejs#49104
Fixes: nodejs#48957
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
RafaelGSS pushed a commit that referenced this pull request Aug 15, 2023
This commit adds the delimiters ^ and $ to the regex that matches the
MIME types for `data:` URLs.

PR-URL: #49104
Fixes: #48957
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
@UlisesGascon UlisesGascon mentioned this pull request Aug 15, 2023
RafaelGSS pushed a commit to RafaelGSS/node that referenced this pull request Aug 15, 2023
This commit adds the delimiters ^ and $ to the regex that matches the
MIME types for `data:` URLs.

PR-URL: nodejs#49104
Fixes: nodejs#48957
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
rluvaton pushed a commit to rluvaton/node that referenced this pull request Aug 15, 2023
This commit adds the delimiters ^ and $ to the regex that matches the
MIME types for `data:` URLs.

PR-URL: nodejs#49104
Fixes: nodejs#48957
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
@andremralves andremralves deleted the fix-mime branch August 16, 2023 05:02
RafaelGSS pushed a commit that referenced this pull request Aug 16, 2023
This commit adds the delimiters ^ and $ to the regex that matches the
MIME types for `data:` URLs.

PR-URL: #49104
Fixes: #48957
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
RafaelGSS pushed a commit that referenced this pull request Aug 17, 2023
This commit adds the delimiters ^ and $ to the regex that matches the
MIME types for `data:` URLs.

PR-URL: #49104
Fixes: #48957
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
targos pushed a commit that referenced this pull request Nov 27, 2023
This commit adds the delimiters ^ and $ to the regex that matches the
MIME types for `data:` URLs.

PR-URL: #49104
Fixes: #48957
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
This commit adds the delimiters ^ and $ to the regex that matches the
MIME types for `data:` URLs.

PR-URL: nodejs/node#49104
Fixes: nodejs/node#48957
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
This commit adds the delimiters ^ and $ to the regex that matches the
MIME types for `data:` URLs.

PR-URL: nodejs/node#49104
Fixes: nodejs/node#48957
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.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. commit-queue-failed An error occurred while landing this pull request using GitHub Actions. 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.

MIME type overmatch in data URLs
4 participants