0

Url looks like: /getUserConnectionsList?login=**********&pagelimit=25&page=1&ot=asc&of=openDatetime&section=userActivity

@PostMapping(path = "getUserConnectionsList", params = {"login"})
public String getUserConnectionsList(@RequestParam String login,
                                     @RequestParam(required = false) String pagelimit,
                                     @RequestParam(required = false) String page,
                                     @RequestParam(required = false) String from,
                                     @RequestParam(required = false) String to,
                                     @RequestParam(required = false) String ot,
                                     @RequestParam(required = false) String of) {
 
log.debug("test: {}, {}, {}, {}", login, page, ot, of);

And output looks like:

test: **********, 1, asc, openDatetime§ion=userActivity

It seems obvious that the following characters after openDatetime - "&sect", are interpreted as HTML ENTITY '§'. But I would like a know on how to solve this problem at the level of mapping, in order to avoid further situations when characters in a string are converted to a value I do not need.

*The error is reproducible on any http-client apps.

*Using the latest available version of springframework at the moment 2.6.2.

*Using header content-type: text/plain;charset=UTF-8

Yuriy
  • 11
  • 4
  • I can't reproduce it. I've created simple spring boot application with single rest controller and it works as expected. Try using curl to call your http endpoint. It might be your client code doing the conversion. – vbezhenar Dec 29 '21 at 13:26

1 Answers1

0

My guess: You are encoding your URLs in your HTML incorrectly. Keep in mind in HTML & must be encoded as &, if the & is followed by a valid entity. As a general rule you should just do it always.

See Do I encode ampersands in <a href...>?

Example:

WRONG:

<form action="/getUserConnectionsList?login=**********&pagelimit=25&page=1&ot=asc&of=openDatetime&section=userActivity">
</form>

RIGHT:

<form action="/getUserConnectionsList?login=**********&amp;pagelimit=25&amp;page=1&amp;ot=asc&amp;of=openDatetime&amp;section=userActivity">
</form>

Considering you are using Spring, you are probably using Thymeleaf. If you use th:action and an @{...} expression, it will do the encoding for you:

<form th:action="@{'/getUserConnectionsList'(login='**********', pagelimit=25, page=1, ot=asc, of=openDatetime, section=userActivity")}">
</form>
RoToRa
  • 37,635
  • 12
  • 69
  • 105