It looks like that PathPattern works inconsistently whit with * and ** rules in matching a string without trailing '/

For example: /resources/* matches /resources/path but not /resources /resources/** matches both /resources/path AND /resources

The same holds also for {path} and {*path}, but at least the behavior is documented for {*path}.

I wonder if this ambiguity is by design or if it can be considered a bug. If this is the expected behavior, it would be good to document it also for **.

Can be reproduced with the following test

    @Test
    void myTest() {
        HttpServletRequest request = new MockHttpServletRequest("GET", "/resources");
        assertFalse(PathPatternRequestMatcher.pathPattern("/resources/*").matches(request));
        assertFalse(PathPatternRequestMatcher.pathPattern("/resources/{path}").matches(request));

         // The following assertions fail    
        assertFalse(PathPatternRequestMatcher.pathPattern("/resources/**").matches(request));
        assertFalse(PathPatternRequestMatcher.pathPattern("/resources/{*path}").matches(request));
    }

Comment From: bclozel

Hello @mcollovati and thanks for reaching out.

The core difference here is that * and {name} consider a single path segment, which is the part after a path separator / and before the next separator, if present. On the other hand, ** and {*path} consider zero or more entire path segments and inner separators.

So /resources/{segment} does not match /resources because the second path segment required by the pattern does not exist in the request. /resources/{*path} matches /resources because {*path} matches for zero or more segments (here, zero).

Another way to look at it is that * and {name} match similar requests but the second one extracts the content as a variable. Same applies to ** and {*path}. I've prepared updates that will hopefully improve the documentation.

Comment From: mcollovati

@bclozel Thanks for the clarification!

Comment From: github-actions[bot]

Fixed via 8bb63081a87cadb7fbf8ba306187564b9d2f0b1c