From 0d3e5db3fff484a1d2812086044660b82c19c910 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 5 Jul 2019 07:36:35 +0100 Subject: [PATCH] Compare suffix patterns by length Closes gh-23125 --- .../main/java/org/springframework/util/AntPathMatcher.java | 5 ++++- .../java/org/springframework/util/AntPathMatcherTests.java | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java index 0463e9e4bb0..be00ab8fc49 100644 --- a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java +++ b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java @@ -776,7 +776,10 @@ public class AntPathMatcher implements PathMatcher { return 1; } - if (info1.isPrefixPattern() && info2.getDoubleWildcards() == 0) { + if (info1.isPrefixPattern() && info2.isPrefixPattern()) { + return info2.getLength() - info1.getLength(); + } + else if (info1.isPrefixPattern() && info2.getDoubleWildcards() == 0) { return 1; } else if (info2.isPrefixPattern() && info1.getDoubleWildcards() == 0) { diff --git a/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java b/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java index 1e9c53865cf..73278dd0997 100644 --- a/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java +++ b/spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java @@ -481,8 +481,9 @@ public class AntPathMatcherTests { assertThat(comparator.compare("/hotels/**", "/hotels/{hotel}/bookings/{booking}/cutomers/{customer}")).isEqualTo(1); assertThat(comparator.compare("/hotels/foo/bar/**", "/hotels/{hotel}")).isEqualTo(1); assertThat(comparator.compare("/hotels/{hotel}", "/hotels/foo/bar/**")).isEqualTo(-1); - assertThat(comparator.compare("/hotels/**/bookings/**", "/hotels/**")).isEqualTo(2); - assertThat(comparator.compare("/hotels/**", "/hotels/**/bookings/**")).isEqualTo(-2); + + // gh-23125 + assertThat(comparator.compare("/hotels/*/bookings/**", "/hotels/**")).isEqualTo(-11); // SPR-8683 assertThat(comparator.compare("/**", "/hotels/{hotel}")).isEqualTo(1);