PathPattern#matchAndExtract minor refactoring

Consistent behavior with matches(PathContainer), the two had slightly
different logic for handling of empty paths.

Make matchAndExtract independantly usable without the need to call
matches(PathContainer) first. Essentially no longer raising ISE if the
pattern doesn't match but simply returning null.
This commit is contained in:
Rossen Stoyanchev
2017-08-02 16:31:06 +02:00
parent dccedd5ad5
commit 62fa20fd6f
3 changed files with 21 additions and 29 deletions

View File

@@ -768,20 +768,10 @@ public class PathPatternTests {
checkCapture("/{page}.*", "/42.html", "page", "42");
checkCapture("/A-{B}-C", "/A-b-C", "B", "b");
checkCapture("/{name}.{extension}", "/test.html", "name", "test", "extension", "html");
try {
checkCapture("/{one}/", "//", "one", "");
fail("Expected exception");
}
catch (IllegalStateException e) {
assertEquals("Pattern \"/{one}/\" is not a match for \"//\"", e.getMessage());
}
try {
checkCapture("", "/abc");
fail("Expected exception");
}
catch (IllegalStateException e) {
assertEquals("Pattern \"\" is not a match for \"/abc\"", e.getMessage());
}
assertNull(checkCapture("/{one}/", "//"));
assertNull(checkCapture("", "/abc"));
assertEquals(0, checkCapture("", "").getUriVariables().size());
checkCapture("{id}", "99", "id", "99");
checkCapture("/customer/{customerId}", "/customer/78", "customerId", "78");