Skip to content

fix(template): treat invalid expression pattern modifier as literal#3459

Open
seonwooj0810 wants to merge 1 commit into
OpenFeign:masterfrom
seonwooj0810:fix/issue-2739-invalid-pattern-modifier
Open

fix(template): treat invalid expression pattern modifier as literal#3459
seonwooj0810 wants to merge 1 commit into
OpenFeign:masterfrom
seonwooj0810:fix/issue-2739-invalid-pattern-modifier

Conversation

@seonwooj0810

Copy link
Copy Markdown
Contributor

Fixes #2739

Root cause

A header-map value (or any template fragment) such as {test:[abc} is parsed by Expressions.create as a {name:pattern} expression, where the part after : is treated as a regex value modifier. Expression's constructor compiles that modifier eagerly via Pattern.compile(...), so when the modifier is not a valid regular expression ([abcUnclosed character class) a PatternSyntaxException was thrown during template construction. With a Map header value containing brackets/colons this surfaces as the stack trace in the issue (HeaderTemplate.createTemplateExpressions.createPattern.compile).

Change

Expressions.create already returns null to 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: a PatternSyntaxException raised while building the expression is caught and create returns null, so the fragment falls back to a Literal in Template.parseFragment instead of failing template construction. Valid expressions such as {id:[0-9]+} are unaffected.

Test evidence

Added ExpressionsTest.invalidPatternModifierIsTreatedAsLiteralExpressions.create("{test:[abc}") previously threw PatternSyntaxException; it now returns null (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 via git-code-format-maven-plugin:validate-code-format (BUILD SUCCESS); commit carries a DCO Signed-off-by trailer.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When using FeignClient, an error occurs when a value with a special structure is passed in the header map

1 participant