Skip to content

Commit

Permalink
Issue #7891 - Improved RegexPathSpec signature detection with groups
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed May 3, 2022
1 parent 77b47a2 commit ad9b83d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Expand Up @@ -73,6 +73,8 @@ public RegexPathSpec(String regex)
case '^': // ignore anchors
case '$': // ignore anchors
case '\'': // ignore escaping
case '(': // ignore grouping
case ')': // ignore grouping
break;
case '+': // single char quantifier
case '?': // single char quantifier
Expand Down Expand Up @@ -107,7 +109,7 @@ public RegexPathSpec(String regex)
if (forbiddenReason != null)
{
throw new IllegalArgumentException(String.format("%s does not support \\%c (%s) for \"%s\"",
this.getClass().getSimpleName(), c, forbiddenReason));
this.getClass().getSimpleName(), c, forbiddenReason, declaration));
}
switch (c)
{
Expand All @@ -123,7 +125,7 @@ public RegexPathSpec(String regex)
break;
}
}
else
else // not escaped
{
signature.append('l'); // literal (exact)
}
Expand Down
Expand Up @@ -166,10 +166,26 @@ public void testSuffixSpecMiddle()
assertMatches(spec, "/middle/");

assertNotMatches(spec, "/a.do");
assertNotMatches(spec, "/a");
assertNotMatches(spec, "/aa");
assertNotMatches(spec, "/aa/bb");
assertNotMatches(spec, "/aa/bb.do/more");
assertNotMatches(spec, "/a/middle");
assertNotMatches(spec, "/middle");
}

@Test
public void testSuffixSpecMiddleWithGroupings()
{
RegexPathSpec spec = new RegexPathSpec("^(.*)/middle/(.*)$");
assertEquals("^(.*)/middle/(.*)$", spec.getDeclaration(), "Spec.pathSpec");
assertEquals("^(.*)/middle/(.*)$", spec.getPattern().pattern(), "Spec.pattern");
assertEquals(2, spec.getPathDepth(), "Spec.pathDepth");
assertEquals(PathSpecGroup.SUFFIX_GLOB, spec.getGroup(), "Spec.group");

assertMatches(spec, "/a/middle/c.do");
assertMatches(spec, "/a/b/c/d/middle/e/f");
assertMatches(spec, "/middle/");

assertNotMatches(spec, "/a.do");
assertNotMatches(spec, "/a/middle");
assertNotMatches(spec, "/middle");
}

@Test
Expand Down

0 comments on commit ad9b83d

Please sign in to comment.