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

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

Closed
spring-projects-issues opened this issue Sep 6, 2015 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

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

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

Hm, indeed this is not deliberate but rather a side effect of using UriComponentsBuilder. The MockMvcRequestBuilders class offers two sets of methods -- one accepting a URI template string and the other a java.net.URI. Perhaps the second should not result in use of UriComponentsBuilder internally. That seems to be out of convenience.

@spring-projects-issues
Copy link
Collaborator Author

Oliver Lehmann commented

Using URI instead of String was my first try to "work around" this issue. But using URI or String makes no difference. Double-slashes are always replaced by a single slash.

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

See commit df171f.

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.2.2 milestone Jan 11, 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) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants