简体   繁体   中英

Spring Boot @RequestParam truncating URL's passed in with ?'s and #'s

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!

You need to use Percent Encoding on the incoming url.

# is %23

? is %3F

使用encodeURIComponent对参数url进行编码。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM