1

I've seen a similar issue to this when using Spring MVC @PathValue but none of the solutions online for that worked for this issue.

I am currently working on an app where users will enter a URL and @RequestParam seems to truncate the URL's passed in on ?'s and #'s.

@RequestMapping(value = "/route/path", method = RequestMethod.GET, produces = "application/json")
public Value method(@RequestParam(value="url") String url, HttpServletRequest request) throws Exception {
    //execute code

Now for example if someone were to pass in localhost:8080/route/path?url=https://css-tricks.com/hash-tag-links-padding/#article-header-id-0 the query would be truncated to url=https://css-tricks.com/hash-tag-links-padding/

The same thing seems to happen with '&' as well. I've tried a myriad of solutions around regexes, Bean configuration, and overriding configurePathMatch in WebMvcConfigurerAdapter.

Has anyone else had this issue? If so, did you find a work around? Thanks in adavance!

Brian
  • 13
  • 4
  • have you tried this ? http://stackoverflow.com/questions/3526523/spring-mvc-pathvariable-getting-truncated – AchillesVan Jul 26 '16 at 21:34
  • or perhaps its because you are using Chromes Rest Console to test – AchillesVan Jul 26 '16 at 21:51
  • Because that is how URLs are supposed to work. Everything after `#` is for the client only a anchor. If you want it passed to the server you would need to url-encode it. Trying to solve it on the server side isn't going to help you. – M. Deinum Jul 27 '16 at 06:18

2 Answers2

0

You need to use Percent Encoding on the incoming url.

# is %23

? is %3F

UserF40
  • 3,533
  • 2
  • 23
  • 34
0

Use encodeURIComponent to encode your parameter url.

Blank
  • 12,308
  • 1
  • 14
  • 32