fix(template): treat invalid expression pattern modifier as literal#3459
Open
seonwooj0810 wants to merge 1 commit into
Open
fix(template): treat invalid expression pattern modifier as literal#3459seonwooj0810 wants to merge 1 commit into
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>
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.
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.