@Test // SPR-13286 public void caseInsensitive() { PathPatternParser pp = new PathPatternParser(); pp.setCaseSensitive(false); PathPattern p = pp.parse("/group/{groupName}/members"); assertMatches(p,"/group/sales/members"); assertMatches(p,"/Group/Sales/Members"); assertMatches(p,"/group/Sales/members"); }
pp.setCaseSensitive(false); PathPattern p = pp.parse("abc"); assertMatches(p,"AbC"); assertNoMatch(p,"def"); p = pp.parse("fOo"); assertMatches(p,"FoO"); p = pp.parse("/fOo/bAr"); assertMatches(p,"/FoO/BaR"); assertNoMatch(p,"/FoO/BaR"); p = pp.parse("/fOO/bAr"); assertMatches(p,"/fOO/bAr"); assertMatches(p,"abc"); assertMatches(p,"ABC"); p = pp.parse("{foo:[A-Z]*}"); assertNoMatch(p,"abc"); assertMatches(p,"ABC"); assertMatches(p,"AbC"); p = pp.parse("fO?"); assertMatches(p,"FoO"); p = pp.parse("/fO?/bA?"); assertMatches(p,"/FoO/BaR"); assertNoMatch(p,"/bAr/fOo"); assertNoMatch(p,"/FoO/BaR"); p = pp.parse("/fO?/bA?");
assertMatches(pp,"/resource"); assertMatches(pp,"/resource"); assertMatches(pp,"/resource/"); assertNoMatch(pp,"/resource//"); pp = parse("/resource/"); assertNoMatch(pp,"/resource"); assertMatches(pp,"/resource/"); assertNoMatch(pp,"/resource//"); assertMatches(pp,"/resource"); assertMatches(pp,"/resource/"); assertNoMatch(pp,"/resource//"); pp = parse("/res?urce/"); assertNoMatch(pp,"/resource"); assertMatches(pp,"/resource/"); assertNoMatch(pp,"/resource//"); assertMatches(pp,"/resource"); assertEquals("resource",pp.matchAndExtract(toPathContainer("/resource")).getUriVariables().get("var")); assertMatches(pp,"/resource/"); assertEquals("resource",pp.matchAndExtract(toPathContainer("/resource/")).getUriVariables().get("var")); assertNoMatch(pp,"/resource//"); pp = parse("/{var}/"); assertNoMatch(pp,"/resource"); assertMatches(pp,"/resource/"); assertEquals("resource",pp.matchAndExtract(toPathContainer("/resource/")).getUriVariables().get("var")); assertNoMatch(pp,"/resource//"); assertMatches(pp,"/resource");
PathPattern pp; pp = new PathPatternParser().parse("/{foo}"); assertMatches(pp,"/abc"); assertNoMatch(pp,"/"); assertNoMatch(pp,"//"); assertMatches(pp,"/abc/def"); assertNoMatch(pp,"/def"); assertNoMatch(pp,"/"); assertMatches(pp,"/abc/boo"); assertMatches(pp,"/a/boo"); assertNoMatch(pp,"/boo"); assertNoMatch(pp,"//boo"); assertMatches(pp,"/abc"); assertNoMatch(pp,"/"); pp = parse("/{word:[a-z]*}"); assertNoMatch(pp,"/1"); assertMatches(pp,"/a"); assertNoMatch(pp,"/"); assertMatches(pp,"/abcdef"); assertNoMatch(pp,"/"); assertNoMatch(pp,"//"); ppp.setMatchOptionalTrailingSeparator(true); pp = ppp.parse("/****");
@Test public void extractUriTemplateVariables() throws Exception { assertMatches(parse("{hotel}"),"1"); assertMatches(parse("/hotels/{hotel}"),"/hotels/1"); checkCapture("/hotels/{hotel}", "/hotels/1", "hotel", "1"); checkCapture("/h?tels/{hotel}", "/hotels/1", "hotel", "1"); checkCapture("/hotels/{hotel}/bookings/{booking}", "/hotels/1/bookings/2", "hotel", "1", "booking", "2"); checkCapture("/*/hotels/*/{hotel}", "/foo/hotels/bar/1", "hotel", "1"); checkCapture("/{page}.html", "/42.html", "page", "42"); checkNoMatch("/{var}","/"); checkCapture("/{page}.*", "/42.html", "page", "42"); checkCapture("/A-{B}-C", "/A-b-C", "B", "b"); checkCapture("/{name}.{extension}", "/test.html", "name", "test", "extension", "html"); assertNull(checkCapture("/{one}/", "//")); assertNull(checkCapture("", "/abc")); assertEquals(0, checkCapture("", "").getUriVariables().size()); checkCapture("{id}", "99", "id", "99"); checkCapture("/customer/{customerId}", "/customer/78", "customerId", "78"); checkCapture("/customer/{customerId}/banana", "/customer/42/banana", "customerId", "42"); checkCapture("{id}/{id2}", "99/98", "id", "99", "id2", "98"); checkCapture("/foo/{bar}/boo/{baz}", "/foo/plum/boo/apple", "bar", "plum", "baz", "apple"); checkCapture("/{bla}.*", "/testing.html", "bla", "testing"); PathPattern.PathMatchInfo extracted = checkCapture("/abc", "/abc"); assertEquals(0, extracted.getUriVariables().size()); checkCapture("/{bla}/foo","/a/foo"); }
@Test public void multipleSeparatorsInPattern() { PathPattern pp = parse("a//b//c"); assertEquals("Literal(a) Separator(/) Separator(/) Literal(b) Separator(/) Separator(/) Literal(c)", pp.toChainString()); assertMatches(pp,"a//b//c"); assertEquals("Literal(a) Separator(/) WildcardTheRest(/**)",parse("a//**").toChainString()); checkMatches("///abc", "///abc"); checkNoMatch("///abc", "/abc"); checkNoMatch("//", "/"); checkMatches("//", "//"); checkNoMatch("///abc//d/e", "/abc/d/e"); checkMatches("///abc//d/e", "///abc//d/e"); checkNoMatch("///abc//{def}//////xyz", "/abc/foo/xyz"); checkMatches("///abc//{def}//////xyz", "///abc//p//////xyz"); }