Repository navigation
fix(template): treat invalid expression pattern modifier as literal - #3459
seonwooj0810 wants to merge 1 commit into
Conversation
A header-map (or any template) value such as "{test:[abc}" parses as a
{name:pattern} expression, but the ':' value modifier ("[abc") is not a
valid regular expression. Expression's constructor compiles it eagerly
with Pattern.compile, so an invalid modifier threw PatternSyntaxException
during template construction (OpenFeigngh-2739) instead of the value being used
as-is.
Expressions.create already returns null to signal "this is not a usable
expression, treat the chunk as a literal". Extend that contract to a
PatternSyntaxException from the value modifier: catch it and return null
so the chunk falls back to a literal. Valid expressions such as
{id:[0-9]+} are unaffected.
Signed-off-by: seonwoo_jung <79202163+seonwooj0810@users.noreply.github.com>
|
Closing this as already fixed upstream. While rebasing onto current Test coverage there is a superset of mine too — Nothing left to do here — thanks to whoever picked it up. Closing to keep the review queue clean. |
Fixes #2739
Root cause
A header-map value (or any template fragment) such as
{test:[abc}is parsed byExpressions.createas a{name:pattern}expression, where the part after:is treated as a regex value modifier.Expression's constructor compiles that modifier eagerly viaPattern.compile(...), so when the modifier is not a valid regular expression ([abc→ Unclosed character class) aPatternSyntaxExceptionwas thrown during template construction. With aMapheader value containing brackets/colons this surfaces as the stack trace in the issue (HeaderTemplate.create→Template→Expressions.create→Pattern.compile).Change
Expressions.createalready returnsnullto signal "this is not a usable expression — treat the chunk as a literal" (e.g. for nested expressions and non-simple candidates). This extends that existing contract: aPatternSyntaxExceptionraised while building the expression is caught andcreatereturnsnull, so the fragment falls back to aLiteralinTemplate.parseFragmentinstead of failing template construction. Valid expressions such as{id:[0-9]+}are unaffected.Test evidence
Added
ExpressionsTest.invalidPatternModifierIsTreatedAsLiteral—Expressions.create("{test:[abc}")previously threwPatternSyntaxException; it now returnsnull(literal).Verification done: built and ran the affected tests with the project toolchain —
./mvnw -pl core test -Dtest='feign.template.**'→ 80 tests pass (including the new one), no regression; code formatting validated viagit-code-format-maven-plugin:validate-code-format(BUILD SUCCESS); commit carries a DCOSigned-off-bytrailer.