Skip to content

Double slashes (optional Path variable) removed via MockHttpServletRequestBuilder [SPR-13435] #18014

@spring-projects-issues

Description

@spring-projects-issues

Oliver Lehmann opened SPR-13435 and commented

When running a Unittest with MockHttpServletRequestBuilder I have the following URI for example:

/test//currentlyValid/0

After Calling MockMvcRequestBuilders.get(uri); The uri inside the returning builder is set to

/test/currentlyValid/0

The double slash was replaced by a single slash!

This was done by the following code in org.springframework.web.util.UriComponentsBuilder.FullPathComponentBuilder

public PathComponent build() {
     if (this.path.length() == 0) {
          return null;
     }
     String path = this.path.toString();
     while (true) {
          int index = path.indexOf("//");
          if (index == -1) {
                   break;
          }
          path = path.substring(0, index) + path.substring(index + 1);
     }
     return new HierarchicalUriComponents.FullPathComponent(path);
}

What is the point in replacing double slashes by a single slash? How am I supposed to test usecases with optional path variables?
For me, this feels like a bug to report....


Affects: 4.1.7

Referenced from: commits df171ff

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