Skip to content

Path variable doesn't handle periods correctly [SPR-16400] #20946

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

Closed
spring-projects-issues opened this issue Jan 18, 2018 · 2 comments
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply

Comments

@spring-projects-issues
Copy link
Collaborator

Michel Jung opened SPR-16400 and commented

Assume this controller:

@SpringBootApplication
@RestController
public class PathBugApplication {

	public static void main(String[] args) {
		SpringApplication.run(PathBugApplication.class, args);
	}

	@RequestMapping(path = "/{token}", method = RequestMethod.GET)
	public String bug(@PathVariable("token") String token) {
		return token;
	}
}

When calling http://localhost:8080/a.b.c, what is the expected output?

  1. a.b.c
  2. a.b

If 2. then everything is fine and I just need to RTFM (can you point me to it?)
If 1. then there's a bug, because the result is 2.


Affects: 4.3.13

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jan 19, 2018

Brian Clozel commented

This is the expected behavior.
By default, Spring MVC enables suffix pattern matching - meaning that if you declare a "/something" pattern, this will also match automatically "/something.*". This is done to allow content negotiation using the file extension: "/something.json" will try to produce JSON, etc.

This is described in the reference documentation.

You can choose one of those solutions:

  • use setUseSuffixPatternMatch(false) on the path matching configuration (see reference documentation)
  • if you rely on suffix pattern matching in other places, you can alter your pattern to catch the extension, like "/{token:.+}"

Note that this default has been changed in Spring Boot 2.0.

@spring-projects-issues
Copy link
Collaborator Author

Michel Jung commented

Thank you very much for taking the time to explain it to me!

@spring-projects-issues spring-projects-issues added type: bug A general bug status: declined A suggestion or change that we don't feel we should currently apply in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug A general bug label Jan 12, 2019
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) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

2 participants