When path contains an encoded string like /path/to/aaaa%20bbb, rewriting fails with an exception
java.lang.IllegalArgumentException: Invalid character ' ' for PATH in "/path/to/aaa bbb"
at org.springframework.web.util.HierarchicalUriComponents.verifyUriComponent(HierarchicalUriComponents.java:416)
at org.springframework.web.util.HierarchicalUriComponents.access$200(HierarchicalUriComponents.java:53)
at org.springframework.web.util.HierarchicalUriComponents$FullPathComponent.verify(HierarchicalUriComponents.java:912)
at org.springframework.web.util.HierarchicalUriComponents.verify(HierarchicalUriComponents.java:380)
at org.springframework.web.util.HierarchicalUriComponents.<init>(HierarchicalUriComponents.java:145)
at org.springframework.web.util.UriComponentsBuilder.buildInternal(UriComponentsBuilder.java:483)
at org.springframework.web.util.UriComponentsBuilder.build(UriComponentsBuilder.java:472)
at com.github.mkopylec.charon.forwarding.interceptors.rewrite.CommonRegexRequestPathRewriter.rewritePath(CommonRegexRequestPathRewriter.java:51)
at com.github.mkopylec.charon.forwarding.interceptors.rewrite.RegexRequestPathRewriter.forward(RegexRequestPathRewriter.java:22)
...
It's because in CommonRegexRequestPathRewriter#rewritePath you get the path in decoded form
String requestPath = uri.getPath();
then rewrite it and build a new path with encoded parameter set to true. Which is wrong.
URI rewrittenUri = fromUri(uri)
.replacePath(rewrittenPath)
.build(true)
.toUri();
When path contains an encoded string like /path/to/aaaa%20bbb, rewriting fails with an exception
It's because in
CommonRegexRequestPathRewriter#rewritePath
you get the path in decoded formString requestPath = uri.getPath();
then rewrite it and build a new path with encoded parameter set to true. Which is wrong.