Fix escape() corrupting the unescaped prefix of its result - #2501
Merged
Merged
Conversation
js_escape seeded its output builder with the VarScope parameter instead of the input string before truncating, so any leading run of unescaped characters was replaced by the scope object's toString().
Collaborator
Contributor
Author
|
Yes, that's the one. It renamed the input |
Contributor
|
And because everything can be converted to a string by the string builder itself we didn't catch the problem. 😕 |
Collaborator
|
Great -- thanks! |
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.
I hit this reading
js_escapenext toencode(). The outputStringBuilderis created lazily on the first character that needs escaping, and it is meant to be seeded with the already-processed prefixstr[0..k). It instead doessb.append(s), wheresis theVarScopeparameter, and thensetLength(k), so the leading run of safe characters is overwritten by the firstkcharacters of the scope object'stoString()(or NUL padding when that is shorter). Every input that starts with an unescaped run before its first escaped character comes back corrupted.encode()a few lines down uses the same lazy-init idiom correctly withstr, which is what this changesjs_escapeto do. I addedGlobalEscapeTestcovering prefixes of different lengths, a leading escaped char, an all-unescaped string, and a%uXXXXescape; the first group fails before the change and passes after.