Skip to content

Give warning when using capturing patterns with the AntPathMatcher #27688

Closed

Description

@dsyer

This fails:

@GetMapping("/resource/{*tail}")
public Object statics(@PathVariable String tail) {...}

with

Required URI template variable 'tail' for method parameter type String is not present

In fact what you need is

@GetMapping("/resource/{*tail}")
public Object statics(@PathVariable("*tail") String tail) {...}

This isn't really obvious from either the error message or the docs. Maybe we should support the first variant anyway?

Activity

  1. self-assigned this
    on Nov 16, 2021
  2. added
    in: webIssues in web modules (web, webmvc, webflux, websocket)
    on Nov 16, 2021
  3. poutsma commented on Nov 17, 2021

    @poutsma
    Contributor

    I can't reproduce this. With the following handler method:

    @GetMapping("/resources/{*tail}")
    	public String handle(@PathVariable String tail) {
    		return tail;
    	}
    

    a request for /resources/foo/bar/baz returns /foo/bar/baz.

  4. added
    status: invalidAn issue that we don't feel is valid
    and removed on Nov 17, 2021
  5. changed the title [-]Better convention for tail path resolution with @PathVariable[/-] [+]Give warning when using capturing patterns with the AntPathMatcher[/+] on Nov 17, 2021
  6. added and removed
    status: invalidAn issue that we don't feel is valid
    on Nov 17, 2021
  7. added this to the 5.3.14 milestone on Nov 17, 2021
  8. poutsma commented on Nov 17, 2021

    @poutsma
    Contributor

    This issue was probably due to using the default AntPathMatcher in combination with a capturing pattern ({*foo}). We should throw an exception when users do so.

  9. added a commit that references this issue on Nov 17, 2021
    5fbdd6d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions