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

handling of path segments with leading spaces in HierarchicalUriComponents #32705

Open
diamondT opened this issue Apr 25, 2024 · 0 comments
Open
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: waiting-for-triage An issue we've not yet triaged or decided on

Comments

@diamondT
Copy link

diamondT commented Apr 25, 2024

hi,

was wondering, is there a reason that path segments are trimmed in HierarchicalUriComponents.FullPathComponent?

String[] segments = StringUtils.tokenizeToStringArray(getPath(), PATH_DELIMITER_STRING);

for example the following test will fail

	@Test
	void pathWithLeadingSpace() {
		String theUrl = "https://path.com/seg1/seg2/ seg-with-leading-space/file.png";
		UriComponents uriComponents = UriComponentsBuilder.fromUriString(theUrl).build();
		assertThat(uriComponents.getPathSegments()).hasSameElementsAs(
				List.of("seg1", "seg2", " seg-with-leading-space", "file.png")
		);
	}

mind you, .toUri() still returns the correct thing (https://path.com/seg1/seg2/%20seg-with-leading-space/file.png), it's just that it seems weird to store the "wrong" path components.

looks like a simple change for the above line like

String[] segments = StringUtils.tokenizeToStringArray(getPath(), PATH_DELIMITER_STRING, false, true);

should do the trick.

insights?

thanks,

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 25, 2024
@jhoeller jhoeller added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Apr 25, 2024
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: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

No branches or pull requests

3 participants