From 068412e6255a9211dc5d46e04990a26495a2414b Mon Sep 17 00:00:00 2001 From: aizu-m Date: Mon, 22 Jun 2026 17:00:00 +0530 Subject: [PATCH] use correct error key for over-range hex escape in RegexParser --- .../apache/xmlbeans/impl/regex/RegexParser.java | 2 +- .../java/misc/checkin/RegularExpressionTest.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/xmlbeans/impl/regex/RegexParser.java b/src/main/java/org/apache/xmlbeans/impl/regex/RegexParser.java index 5202de2c9..541f61f20 100644 --- a/src/main/java/org/apache/xmlbeans/impl/regex/RegexParser.java +++ b/src/main/java/org/apache/xmlbeans/impl/regex/RegexParser.java @@ -1054,7 +1054,7 @@ int decodeEscaped() throws ParseException { if (this.read() != T_CHAR || (v2 = hexChar(this.chardata)) < 0) throw ex("parser.descape.1", this.offset - 1); uv2 = uv2 * 16 + v2; - if (uv2 > Token.UTF16_MAX) throw ex("parser.descappe.4", this.offset - 1); + if (uv2 > Token.UTF16_MAX) throw ex("parser.descape.4", this.offset - 1); c = uv2; break; } diff --git a/src/test/java/misc/checkin/RegularExpressionTest.java b/src/test/java/misc/checkin/RegularExpressionTest.java index 38861c585..15424d702 100644 --- a/src/test/java/misc/checkin/RegularExpressionTest.java +++ b/src/test/java/misc/checkin/RegularExpressionTest.java @@ -46,6 +46,20 @@ void testLookbehindRangeAtInputEnd() { assertFalse(new RegularExpression("x(?<=[a-c])").matches("xc")); } + @Test + void testHexEscapeOverflowErrorKey() { + // a \v escape (6 hex digits) whose value is above U+10FFFF was reported with + // the error key "parser.descappe.4", which is not in the message bundle, so + // ResourceBundle.getString threw MissingResourceException instead of the + // ParseException callers expect. The sibling \x{...} path already reports the + // same condition cleanly via "parser.descape.4". + assertThrows(ParseException.class, () -> new RegularExpression("\\v110000")); + assertThrows(ParseException.class, () -> new RegularExpression("\\vFFFFFF")); + assertThrows(ParseException.class, () -> new RegularExpression("\\x{110000}")); + // the top of the Unicode range is still valid and must parse + new RegularExpression("\\v10FFFF"); + } + @Test void testQuantifierOverflow() { // a {min,max} count larger than Integer.MAX_VALUE overflowed the int