* Fixes to backport of #7748 + Backport of #7748 + Fix RegexPathSpec pathInfo + Fix UriTemplatePathSpec pathInfo + Test regression option to 93 behaviour * small optimization Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
parent
0837aadb8e
commit
5fc63bf8e8
|
@ -135,7 +135,7 @@ public class RegexPathSpec extends AbstractPathSpec
|
||||||
Matcher matcher = getMatcher(path);
|
Matcher matcher = getMatcher(path);
|
||||||
if (matcher.matches())
|
if (matcher.matches())
|
||||||
{
|
{
|
||||||
if (matcher.groupCount() >= 1)
|
if (_group == PathSpecGroup.PREFIX_GLOB && matcher.groupCount() >= 1)
|
||||||
{
|
{
|
||||||
int idx = matcher.start(1);
|
int idx = matcher.start(1);
|
||||||
if (idx > 0)
|
if (idx > 0)
|
||||||
|
|
|
@ -345,7 +345,7 @@ public class ServletPathSpec extends AbstractPathSpec
|
||||||
case PREFIX_GLOB:
|
case PREFIX_GLOB:
|
||||||
if (path.length() == (_specLength - 2))
|
if (path.length() == (_specLength - 2))
|
||||||
return null;
|
return null;
|
||||||
return path.substring(_specLength - 2);
|
return _specLength == 2 ? path : path.substring(_specLength - 2);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -353,7 +353,7 @@ public class UriTemplatePathSpec extends AbstractPathSpec
|
||||||
Matcher matcher = getMatcher(path);
|
Matcher matcher = getMatcher(path);
|
||||||
if (matcher.matches())
|
if (matcher.matches())
|
||||||
{
|
{
|
||||||
if (matcher.groupCount() >= 1)
|
if (_group == PathSpecGroup.PREFIX_GLOB && matcher.groupCount() >= 1)
|
||||||
{
|
{
|
||||||
int idx = matcher.start(1);
|
int idx = matcher.start(1);
|
||||||
if (idx > 0)
|
if (idx > 0)
|
||||||
|
|
|
@ -19,7 +19,9 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class RegexPathSpecTest
|
public class RegexPathSpecTest
|
||||||
{
|
{
|
||||||
|
@ -71,6 +73,20 @@ public class RegexPathSpecTest
|
||||||
assertNotMatches(spec, "/rest/list");
|
assertNotMatches(spec, "/rest/list");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPathInfo()
|
||||||
|
{
|
||||||
|
RegexPathSpec spec = new RegexPathSpec("^/test(/.*)?$");
|
||||||
|
assertTrue(spec.matches("/test/info"));
|
||||||
|
assertThat(spec.getPathMatch("/test/info"), equalTo("/test"));
|
||||||
|
assertThat(spec.getPathInfo("/test/info"), equalTo("/info"));
|
||||||
|
|
||||||
|
spec = new RegexPathSpec("^/[Tt]est(/.*)?$");
|
||||||
|
assertTrue(spec.matches("/test/info"));
|
||||||
|
assertThat(spec.getPathMatch("/test/info"), equalTo("/test/info"));
|
||||||
|
assertThat(spec.getPathInfo("/test/info"), nullValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMiddleSpecNoGrouping()
|
public void testMiddleSpecNoGrouping()
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,7 +22,9 @@ import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for URI Template Path Specs
|
* Tests for URI Template Path Specs
|
||||||
|
@ -142,6 +144,20 @@ public class UriTemplatePathSpecTest
|
||||||
assertEquals("b", mapped.get("var"), "Spec.pathParams[var]");
|
assertEquals("b", mapped.get("var"), "Spec.pathParams[var]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPathInfo()
|
||||||
|
{
|
||||||
|
UriTemplatePathSpec spec = new UriTemplatePathSpec("/test/{var}");
|
||||||
|
assertTrue(spec.matches("/test/info"));
|
||||||
|
assertThat(spec.getPathMatch("/test/info"), equalTo("/test"));
|
||||||
|
assertThat(spec.getPathInfo("/test/info"), equalTo("info"));
|
||||||
|
|
||||||
|
spec = new UriTemplatePathSpec("/{x}/test/{y}");
|
||||||
|
assertTrue(spec.matches("/try/test/info"));
|
||||||
|
assertThat(spec.getPathMatch("/try/test/info"), equalTo("/try/test/info"));
|
||||||
|
assertThat(spec.getPathInfo("/try/test/info"), nullValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOneVarPathSpec()
|
public void testOneVarPathSpec()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue