Skip to content

Commit

Permalink
Fixes to backport of #7748
Browse files Browse the repository at this point in the history
+ Backport of #7748
+ Fix RegexPathSpec pathInfo
+ Fix UriTemplatePathSpec pathInfo
+ Test regression option to 93 behaviour

Signed-off-by: Greg Wilkins <gregw@webtide.com>
  • Loading branch information
gregw committed Apr 5, 2022
1 parent 0837aad commit 2a859c0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
Expand Up @@ -135,7 +135,7 @@ public String getPathMatch(String path)
Matcher matcher = getMatcher(path);
if (matcher.matches())
{
if (matcher.groupCount() >= 1)
if (_group == PathSpecGroup.PREFIX_GLOB && matcher.groupCount() >= 1)
{
int idx = matcher.start(1);
if (idx > 0)
Expand Down
Expand Up @@ -353,7 +353,7 @@ public String getPathMatch(String path)
Matcher matcher = getMatcher(path);
if (matcher.matches())
{
if (matcher.groupCount() >= 1)
if (_group == PathSpecGroup.PREFIX_GLOB && matcher.groupCount() >= 1)
{
int idx = matcher.start(1);
if (idx > 0)
Expand Down
Expand Up @@ -19,7 +19,9 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
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.assertTrue;

public class RegexPathSpecTest
{
Expand Down Expand Up @@ -71,6 +73,20 @@ public void testMiddleSpec()
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
public void testMiddleSpecNoGrouping()
{
Expand Down
Expand Up @@ -22,7 +22,9 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
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.assertTrue;

/**
* Tests for URI Template Path Specs
Expand Down Expand Up @@ -142,6 +144,20 @@ public void testMiddleVarPathSpec()
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
public void testOneVarPathSpec()
{
Expand Down

0 comments on commit 2a859c0

Please sign in to comment.