SpringAntMatcherOrderCheck extends AbstractMethodDetection { @VisibleForTesting static boolean matches(String pattern, String text) { if (pattern.equals(text)) { return true; } if (pattern.endsWith("**") && text.startsWith(pattern.substring(0, pattern.length() - 2))) { return true; } boolean antPatternContainsRegExp = pattern.contains("{"); boolean textIsAlsoAnAntPattern = MATCHER_SPECIAL_CHAR.matcher(text).find(); if (pattern.isEmpty() || antPatternContainsRegExp || textIsAlsoAnAntPattern) { return false; } return text.matches(antMatcherToRegEx(pattern)); }    }
@Test void should_match() { assertThat(matches("", "")).isTrue(); assertThat(matches("/abc", "/abc")).isTrue(); assertThat(matches("/abcdef")).isTrue(); assertThat(matches("/abc/*ef", "/abc/ddeef")).isTrue(); assertThat(matches("/abc/?ef", "/abc/def")).isTrue(); }
@Test void should_not_match() { assertThat(matches("", "/def")).isFalse(); assertThat(matches("/abc", "/def")).isFalse(); assertThat(matches("/abcdef", "/abcxdef")).isFalse(); assertThat(matches("/{name:[a-z]}", "/abc")).isFalse(); }