Repository navigation
fix(@angular/build): handle regex literals in source-map comment scanner - #34591
Open
alan-agius4 wants to merge 3 commits into
Open
alan-agius4 wants to merge 3 commits into
alan-agius4 wants to merge 3 commits into
Conversation
Previously, `removeSourceMappingURL` did not track regular expression literals in its state machine. A quote character (`"`, `'`, or `` ` ``) inside a regex literal (such as `/"/`) was misinterpreted as the start of a string literal, inverting string boundaries for the remainder of the file and corrupting valid JavaScript when a subsequent string contained `//# sourceMappingURL=`. Closes angular#34590
There was a problem hiding this comment.
Code Review
This pull request enhances the source-map utility to safely ignore regex literals when stripping source map comments, preventing corruption of string boundaries. It introduces a state machine that tracks preceding keywords and punctuation to distinguish division from regex literals, along with comprehensive unit tests. The review feedback highlights three important edge cases to address: handling postfix/prefix operators like ++ and -- to avoid incorrect regex parsing, supporting Unicode characters in identifiers, and adding the missing default keyword to the list of preceding keywords.
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
Sign up for free
to 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.
Previously,
removeSourceMappingURLdid not track regular expression literals in its state machine. A quote character (",', or`) inside a regex literal (such as/"/) was misinterpreted as the start of a string literal, inverting string boundaries for the remainder of the file and corrupting valid JavaScript when a subsequent string contained//# sourceMappingURL=.Closes #34590