GROOVY-12233: StringEscapeUtils.unescapeJava mis-decodes and silently… - #2763
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Tightens groovy.json.StringEscapeUtils.unescapeJava Unicode-escape handling to match Java/JavaScript \uXXXX grammar and to fail fast (with JsonException) on malformed escapes instead of mis-decoding or silently dropping input.
Changes:
- Validate
\uescapes as exactly four ASCII hex digits (rejects signs and non-ASCII digits thatInteger.parseInt(..., 16)would otherwise accept). - Reject truncated
\uescapes at end-of-input (previously digits could be silently discarded). - Expand test coverage for malformed and boundary-case Unicode escapes; align invalid-unicode exception type to
JsonException.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| subprojects/groovy-json/src/main/java/groovy/json/StringEscapeUtils.java | Enforces strict \uXXXX parsing, throws JsonException on malformed/truncated escapes, adds isHexDigit helper and Javadoc @throws. |
| subprojects/groovy-json/src/test/groovy/groovy/json/StringEscapeUtilsTest.groovy | Adds regression tests for GROOVY-12233 and updates invalid-unicode expectation to JsonException. |
Suppressed comments (1)
subprojects/groovy-json/src/main/java/groovy/json/StringEscapeUtils.java:387
- When the input ends mid-escape (e.g. "\u"),
unicodemay be empty, producing an error message with no escape content. Including the\\uprefix ensures the exception clearly points to a truncated Unicode escape.
if (inUnicode) {
// the string ended in the middle of an escape, so the digits read so far are not a
// value; dropping them silently would lose input the caller never asked us to discard
throw new JsonException("Unable to parse unicode value: " + unicode);
}
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2763 +/- ##
==================================================
+ Coverage 69.9875% 69.9900% +0.0025%
- Complexity 35518 35528 +10
==================================================
Files 1557 1557
Lines 131685 131686 +1
Branches 24172 24174 +2
==================================================
+ Hits 92163 92167 +4
Misses 31189 31189
+ Partials 8333 8330 -3
🚀 New features to boost your workflow:
|
This comment has been minimized.
This comment has been minimized.
… drops malformed \u escapes
paulk-asert
force-pushed
the
groovy12233
branch
from
August 4, 2026 05:07
3f97caf to
0862982
Compare
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.
… drops malformed \u escapes