Skip to content

Query params override path variables #34746

@mmachniak

Description

@mmachniak

Describe the bug
In an application (using Spring Boot 2.7.10) query param is able to override path veriable

Sample

@SpringBootApplication
public class Application {
  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }
  
  @RestController
  static class HelloController {
    public record UrlVariableContainer(String name){}

    @GetMapping("/hello/{name}")
    public String hello(UrlVariableContainer container) {
      return "Hello " + container.name();
    }
  }
}

Current behaviour:

GET http://localhost:8080/hello/Mat?name=Chad

HTTP/1.1 200 
Content-Type: text/plain;charset=UTF-8
Content-Length: 10
Date: Fri, 24 Mar 2023 10:27:17 GMT
Keep-Alive: timeout=60
Connection: keep-alive

Hello Chad

Response code: 200; Time: 8ms (8 ms); Content length: 10 bytes (10 B)

I expected that path variable would not be overrided by query param and response will be "Hello Mat" in this scenario.

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: stackoverflowA question that's better suited to stackoverflow.comstatus: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions