[TEXT-XXX] Support ECMAScript \x unescaping in StringEscapeUtils#589
Open
timdp wants to merge 2 commits intoapache:masterfrom
Open
[TEXT-XXX] Support ECMAScript \x unescaping in StringEscapeUtils#589timdp wants to merge 2 commits intoapache:masterfrom
timdp wants to merge 2 commits intoapache:masterfrom
Conversation
Author
|
My Jira account request got denied and I have a low tolerance for red tape, so I'll just leave this PR here for anyone who cares enough to get it merged. |
Member
|
Hello @timdp |
ecki
reviewed
Jan 1, 2026
| */ | ||
| public static final CharSequenceTranslator UNESCAPE_ECMASCRIPT = UNESCAPE_JAVA; | ||
| public static final CharSequenceTranslator UNESCAPE_ECMASCRIPT = new AggregateTranslator( | ||
| new HexUnescaper(), |
Contributor
There was a problem hiding this comment.
For consistency should be a static constant as well?
ecki
reviewed
Jan 1, 2026
| final int value = Integer.parseInt(hex.toString(), 16); | ||
| writer.write((char) value); | ||
| } catch (final NumberFormatException nfe) { | ||
| throw new IllegalArgumentException("Unable to parse ASCII value: " + hex, nfe); |
Contributor
There was a problem hiding this comment.
We probably need to document the IAE for the unescape functions and translator objects. An Abort is valid, it is a Syntax error in ECMAScript (need to verify the same for Java)
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.
Currently,
StringEscapeUtilsunescapes ECMAScript using the Java strategy.This mostly works, but ECMAScript additionally supports
\xCCescapes, whereCCis a hex code.This PR adds support for that, as well as an initial test.
I took the liberty of making the child translators of the Java aggregate translator reusable, so I could basically extend the list for the ES version. If we prefer to duplicate that code or to use a varargs list or something, I'm absolutely fine with that as well.
I just subscribed to the dev list and requested access to Jira. I will update the PR title once I've created the corresponding issue.