Fix error mark position for PatternParseException
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
This commit is contained in:
parent
52a4097997
commit
fccce54d52
|
@ -30,7 +30,7 @@ class PatternParseFailureAnalyzer extends AbstractFailureAnalyzer<PatternParseEx
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FailureAnalysis analyze(Throwable rootFailure, PatternParseException cause) {
|
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 "
|
"Fix this pattern in your application or switch to the legacy parser implementation with "
|
||||||
+ "'spring.mvc.pathmatch.matching-strategy=ant_path_matcher'.",
|
+ "'spring.mvc.pathmatch.matching-strategy=ant_path_matcher'.",
|
||||||
cause);
|
cause);
|
||||||
|
|
|
@ -36,7 +36,11 @@ class PatternParseFailureAnalyzerTests {
|
||||||
@Test
|
@Test
|
||||||
void patternParseFailureQuotesPattern() {
|
void patternParseFailureQuotesPattern() {
|
||||||
FailureAnalysis failureAnalysis = performAnalysis("/spring/**/framework");
|
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())
|
assertThat(failureAnalysis.getAction())
|
||||||
.contains("Fix this pattern in your application or switch to the legacy parser"
|
.contains("Fix this pattern in your application or switch to the legacy parser"
|
||||||
+ " implementation with 'spring.mvc.pathmatch.matching-strategy=ant_path_matcher'.");
|
+ " implementation with 'spring.mvc.pathmatch.matching-strategy=ant_path_matcher'.");
|
||||||
|
|
Loading…
Reference in New Issue