- Notifications
You must be signed in to change notification settings - Fork20.6k
Manipulation: Don't remove HTML comments from scripts#4906
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
When evaluating scripts, jQuery strips out the possible wrapping HTML commentand a CDATA section. However, all supported browsers are already doing thatwhen loading JS via appending a script tag to the DOM which is how we've beendoing `jQuery.globalEval` since jQuery 3.0.0. jQuery logic was imperfect, e.g.it just stripped the `<!--` and `-->` markers, respectively at the beginning orthe end of the script contents. However, browsers are also stripping everythingfollowing those markers in the same line, treating them as single-line commentsdelimiters; this is now also mandated by ECMAScript 2015 in Annex B. Insteadof fixing the jQuery logic, just let the browser do its thing.We also used to strip CDATA sections. However, this shouldn't be needed as inXML documents they're already not visible when inspecting element contents andin HTML documents they have no meaning. We've preserved that behavior forbackwards compatibility in 3.x but we're removing it for 4.0.Fixesjquerygh-4904
This was referencedJul 15, 2021
timmywil approved these changesJul 15, 2021
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.
Makes sense. LGTM
gibson042 approved these changesJul 19, 2021
timmywil approved these changesJul 19, 2021
mgol added a commit that referenced this pull requestJul 19, 2021
When evaluating scripts, jQuery strips out the possible wrapping HTML commentand a CDATA section. However, all supported browsers are already doing thatwhen loading JS via appending a script tag to the DOM which is how we've beendoing `jQuery.globalEval` since jQuery 3.0.0. jQuery logic was imperfect, e.g.it just stripped the `<!--` and `-->` markers, respectively at the beginning orthe end of the script contents. However, browsers are also stripping everythingfollowing those markers in the same line, treating them as single-line commentsdelimiters; this is now also mandated by ECMAScript 2015 in Annex B. Insteadof fixing the jQuery logic, just let the browser do its thing.We still need to strip CDATA sections for backwards compatibility. Thisshouldn't be needed as in XML documents they're already not visible wheninspecting element contents and in HTML documents they have no meaning butwe're preserving that logic for backwards compatibility. This will be removedcompletely in 4.0.Fixesgh-4904Closesgh-4905Refgh-4906
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading.Please reload this page.
Summary
When evaluating scripts, jQuery strips out the possible wrapping HTML comment
and a CDATA section. However, all supported browsers are already doing that
when loading JS via appending a script tag to the DOM which is how we've been
doing
jQuery.globalEval
since jQuery 3.0.0. jQuery logic was imperfect, e.g.it just stripped the
<!--
and-->
markers, respectively at the beginning orthe end of the script contents. However, browsers are also stripping everything
following those markers in the same line, treating them as single-line comments
delimiters; this is now also mandated by ECMAScript 2015 in Annex B. Instead
of fixing the jQuery logic, just let the browser do its thing.
We also used to strip CDATA sections. However, this shouldn't be needed as in
XML documents they're already not visible when inspecting element contents and
in HTML documents they have no meaning. We've preserved that behavior for
backwards compatibility in 3.x but we're removing it for 4.0.
Fixesgh-4904
-44 bytes
3.x version of this PR:#4905
Checklist