fix: prevent escape fallback from swallowing malformed constructs and enable error test suite - #130
Conversation
… enable error test suite
|
Thanks for submitting the fix! AI identified a minor improvement. Please verify if it's applicable. While this excludes digits, x, N, and u, it omits k, p, and P:
Recommended Fix The full list: noneOf("0123456789xNuckpP") |
| .map(Character::codePointOf) | ||
| .map(Character::toString), | ||
| string("\\").then(one(isNot('x'), "escaped char")).map(String::valueOf))); | ||
| string("\\").then(one(noneOf("0123456789xNu"), "escaped char")).map(String::valueOf))); |
There was a problem hiding this comment.
Let's use noneOf("0123456789xNuckpP")
|
Thanks for the review @fluentfuture! Added |
|
AI suggested me to also change the If the use of |
|
Oh yeah that makes total sense, definitely was not intentional. In JDK regex the unbraced single letter properties like Switching to Thanks again for the quick review and merge. |
Summary of Changes
Prevent Escape Fallback Swallowing Malformed Constructs:
RegexParsers.java, the generic escaped character fallbackstring("\\").then(...)previously only excluded'x'viaisNot('x'). When specific escape constructs failed due to malformed or incomplete syntax (such as\N{}empty name,\N{abcunclosed name,\u123zinvalid hex digits,\uincomplete unicode escape,\08or\0invalid octal escape), the parser fell through and consumed the leading character as a literal escaped character (Literal("N"),Literal("u"),Literal("0"))..as("character name")to the\N{...}name parser.noneOf("0123456789xNu"), preventing digits,x,N, andufrom falling through to literal single-character escapes when their specific syntax fails.Enable and Expand Error Test Suite:
RegexParserErrorTests.javatoRegexParserErrorTest.java(matching Maven Surefire's default**/*Test.javainclude pattern), allowing all 75 error tests to be automatically discovered and executed during standardmvn testruns.RegexParserErrorTest.javacovering\u123z,\u,\08, and\0.ParsersRegexCheckTest.javainmug-errorproneto assert the compile-time diagnosticexpecting <4 hex digits>for\u123z.Validation
Executed full clean test suite across all 16 reactor modules:
mvn clean testpassed with 0 failures and 0 errors.dot-parse: 2,480 tests passed (including all 75 tests inRegexParserErrorTest).mug-errorprone: 929 tests passed.