0

My link:

<a data-pin-do="buttonPin" data-pin-color="white" data-pin-
count="beside" href="https://www.pinterest.com/pin/create/button/?

url=https%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F
&media=https%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg
&description=Next%20stop%3A%20Pinterest">
<img src="https://assets.pinterest.com/images/pidgets/pinit_fg_en_rect_white_20.png" />
</a>

Currently thymeleaf thinks that the & in the url should be followed by an ';' character.

Exception message:

org.xml.sax.SAXParseException: The reference to entity "media" must end with the ';' delimiter.

Is there any way to get rid of the & signs and still have a functional url? Or is there any way to tell thyemleaf to 'overlook' the & signs in the url?

Turtle
  • 1,369
  • 1
  • 17
  • 32

1 Answers1

1

Instead of & you should use the entity &amp; to encode your url like:

href="www.myurl.com?param1=value&amp;param2=value"

Or build it using Link URL Expression @{...} with parameters:

th:href="@{www.myurl.com(param1=${'value1'},param2=${'value2'})}" 

It's not only a Thymeleaf matter. You can find a detailed explanation here: Do I really need to encode & as &amp;?)

Community
  • 1
  • 1
Tobías
  • 6,142
  • 4
  • 36
  • 62