Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give warning when using capturing patterns with the AntPathMatcher #27688

Closed
dsyer opened this issue Nov 16, 2021 · 2 comments
Closed

Give warning when using capturing patterns with the AntPathMatcher #27688

dsyer opened this issue Nov 16, 2021 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@dsyer
Copy link
Member

dsyer commented Nov 16, 2021

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?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 16, 2021
@poutsma poutsma self-assigned this Nov 16, 2021
@rstoyanchev rstoyanchev added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Nov 16, 2021
@poutsma
Copy link
Contributor

poutsma commented Nov 17, 2021

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.

@poutsma poutsma closed this as completed Nov 17, 2021
@poutsma poutsma added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 17, 2021
@poutsma poutsma reopened this Nov 17, 2021
@poutsma poutsma changed the title Better convention for tail path resolution with @PathVariable Give warning when using capturing patterns with the AntPathMatcher Nov 17, 2021
@poutsma poutsma added type: enhancement A general enhancement and removed status: invalid An issue that we don't feel is valid labels Nov 17, 2021
@poutsma poutsma added this to the 5.3.14 milestone Nov 17, 2021
@poutsma
Copy link
Contributor

poutsma commented Nov 17, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants