-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Conversation
Review requested:
|
There was a problem hiding this 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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/^\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?$/i, | |
/^\s*(text|application)\/javascript\s*(;|$)/i, |
There was a problem hiding this comment.
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 🚀
I'd say it's not related to this PR, but |
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. |
@aduh95 I fixed the test failure. |
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
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 |
Landed in 7139198, thanks for the contribution 🎉 |
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>
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>
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>
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>
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>
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 😄.