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

UriComponentsBuilder doesn't recognise #ed path [SPR-15454] #20015

spring-projects-issues opened this issue Apr 17, 2017 · 1 comment

UriComponentsBuilder doesn't recognise #ed path [SPR-15454] #20015

spring-projects-issues opened this issue Apr 17, 2017 · 1 comment
in: web status: declined


Copy link

@spring-projects-issues spring-projects-issues commented Apr 17, 2017

Nilesh Injulkar opened SPR-15454 and commented

This piece of code fails with IllegalArgumentException saying the URL is not a valid HTTP URL.

final String redirectionUrl = "";
 final UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(redirectionUrl).build();

The URL doesn't seem to be matching expected pattern :


Affects: 4.3.7

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 18, 2017

Arjen Poutsma commented

As you already found out, the fromHttpUrl method uses a regular expression to "guess" the component from the URL string given. The regular expression is not (and could not be) a 100% correct at this process, especially considering the fact that the string can also be unencoded (i.e. the string might contain characters that are invalid in a particular part of the URL). This is the case in your example: the # character is not valid as part of the path, and therefore should be escaped with the percent encoding into %23.

The way to solve this is to either use the individual component methods on the builder, so that it knows when a particular component starts and where the next one begins. Alternatively, you can percent-escape the # character in the string you pass to fromHttpURl. Like so:

UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
UriComponents result = builder.scheme("http").host("").path("/path/#/angularpath").queryParam("queryparam", "value").build();


String redirectionUrl = "";
UriComponents result = UriComponentsBuilder.fromHttpUrl(redirectionUrl).build();

@spring-projects-issues spring-projects-issues added type: bug status: declined in: web labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.0 RC1 milestone Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug label Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: web status: declined
None yet

No branches or pull requests

2 participants