Skip to content

Commit

Permalink
Fix error mark position for PatternParseException
Browse files Browse the repository at this point in the history
PatternParseException.toDetailedString() return a String
with a mark to specify the error position in the pattern.
The mark takes place in the second line in the String
returned. Because PatternParseFailureAnalyzer.analyze
appended "Invalid mapping pattern detected:" at the
beginning of the returned String, the mark was not well
positioned.

Now, a "\n" is inserted after "Invalid mapping pattern detected:"
and the mark is well positioned

See gh-38944
  • Loading branch information
FBibonne authored and mhalbritter committed Jan 10, 2024
1 parent 52a4097 commit fccce54
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PatternParseFailureAnalyzer extends AbstractFailureAnalyzer<PatternParseEx

@Override
protected FailureAnalysis analyze(Throwable rootFailure, PatternParseException cause) {
return new FailureAnalysis("Invalid mapping pattern detected: " + cause.toDetailedString(),
return new FailureAnalysis("Invalid mapping pattern detected:\n" + cause.toDetailedString(),
"Fix this pattern in your application or switch to the legacy parser implementation with "
+ "'spring.mvc.pathmatch.matching-strategy=ant_path_matcher'.",
cause);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ class PatternParseFailureAnalyzerTests {
@Test
void patternParseFailureQuotesPattern() {
FailureAnalysis failureAnalysis = performAnalysis("/spring/**/framework");
assertThat(failureAnalysis.getDescription()).contains("Invalid mapping pattern detected: /spring/**/framework");
assertThat(failureAnalysis.getDescription()).contains("""
Invalid mapping pattern detected:
/spring/**/framework
^
""");
assertThat(failureAnalysis.getAction())
.contains("Fix this pattern in your application or switch to the legacy parser"
+ " implementation with 'spring.mvc.pathmatch.matching-strategy=ant_path_matcher'.");
.contains("Fix this pattern in your application or switch to the legacy parser"
+ " implementation with 'spring.mvc.pathmatch.matching-strategy=ant_path_matcher'.");
}

private FailureAnalysis performAnalysis(String pattern) {
Expand Down

0 comments on commit fccce54

Please sign in to comment.