I was trying to register certain URLs for a Filter when I noticed that there is a difference between /*
and /**
patte
IMHO code worths 100 words in this case:
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.springframework.util.AntPathMatcher
class AntPathMatcherTests {
@Test
fun twoAsterisks() {
val pattern = "/api/balance/**"
val matcher = AntPathMatcher()
val matching = { path: String -> matcher.match(pattern, path) }
assertTrue(matching("/api/balance"))
assertTrue(matching("/api/balance/"))
assertTrue(matching("/api/balance/abc"))
assertTrue(matching("/api/balance/abc/"))
assertTrue(matching("/api/balance/abc/update"))
assertFalse(matching("/api/bala"))
}
@Test
fun oneAsterisk() {
val pattern = "/api/balance/*"
val matcher = AntPathMatcher()
val matching = { path: String -> matcher.match(pattern, path) }
assertTrue(matching("/api/balance/"))
assertTrue(matching("/api/balance/abc"))
assertFalse(matching("/api/bala"))
assertFalse(matching("/api/balance"))
assertFalse(matching("/api/balance/abc/"))
assertFalse(matching("/api/balance/abc/update"))
}
}