Thymeleaf parsing error due to link with & - spring

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?

Instead of & you should use the entity & to encode your url like:
href="www.myurl.com?param1=value&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 &?)

Related

find xpath of label with non breaking space

I am trying to get xpath for following html code, but nothing seems to be working. I appreciate your suggestion. I need to get the xpath based on text.
<label class="label" securityidpath="ACCOUNTS_FS.PART_ACCOUNT_HEADER_FS.PART_ACCOUNT_STATUS" title="Part Account Status">Part Account Status:
</label>
FYI, I tried following variant xpath
//label[normalize-space(text())='Part Account Status:\u00a0']
//label[normalize-space(text())='Part Account Status:\u000a']
//label[normalize-space(text())='Part Account Status:\u202f']
and all the options as per following url https://en.wikipedia.org/wiki/Whitespace_character
Thank You,
Yougander
You can use
/label[normalize-space(text())='Part Account Status: ']
Or use the hexadecimal variant   instead of the decimal  .
Also note that XPath uses slashes (and not backslashes) to define paths, so referencing the root node label would be done by /label.
The typo lable instead of label is trivial.
BTW you can avoid the trouble with the entity by using the title attribute in your XPath:
label[normalize-space(#title)='Part Account Status']
your element name is wrong and change UTF character name as HexaDecimal entity values:
//label[normalize-space(text())='Part Account Status: ']
XPATH require forward slash

How to prevent liberty from converting "+" to " " in URL

We had an issue where clients were sending "+" as part of a parameter value without percent-encoding it. After digging in, it looks like converting "+" to " " is from HTML form encoding, but not part of the URL spec.
I found https://www.ibm.com/mysupport/s/question/0D50z00005phvXb/urls-with-or-2b-in-the-path-or-query-are-incorrectly-decoded-to-space?language=en_US which sounds exactly like what we're hitting, but with Liberty 19.0.0.8 (and probably for some time), even excpicitly setting decodeUrlPlusSign="false" doesn't seem to help.
That is, when we call req.getParameter(queryParameterName) it is returning the value with a " " instead of a "+".
I'm setting it in server.xml as follows:
<webContainer disableXPoweredBy="true" decodeUrlPlusSign="false" />
What exactly is decodeUrlPlusSign supposed to do? Is it working as expected?

SyntaxError: Unexpected identifier with xpath

i am learning xpath, and i am trying to get some data from html usint xpath
i found that google chrome has a option to "copy xpath" and it works nice
but doesnt work to this exemple
<div id="site-main">
<header class="main" role="banner">some divs </header>
</div>
i use this on google chrome console
$x("//*[#id="site-main"]/header")
and return "SyntaxError: Unexpected identifier"
i dont see anythin wrong...do you?
$x("//*[#id="site-main"]/header")
^ ^
The marked quotes cause the error — in fact, the string is terminated right after =.
You have to escape the quotes inside the XPath expression. The way of escaping depends on the language you are using. If it's Javascript, then it would be with \:
$x("//*[#id=\"site-main\"]/header")
Also have a look on this question: Escape quotes in JavaScript
You can use single quotes in the xpath query:
$x("//*[#id='site-main']/header")

Error validating HTML through w3c validator

I am trying to validate my site through the w3c validator, but am getting the following error:
Line 62, Column 393: & did not start a character reference. (& probably should have been escaped as &.)
…mysite.com/projects/bnd?page=catagory&id=10">asdas</a> (67)</li><li><a href="
I have fixed all other things, but using & in a URL is not a valid w3c URI. How then could I validate my site?
Use & like this:
<a href="http://mysite.com/projects/bnd?page=catagory&id=10">
search and replace the & at line 62 with&

Xquery error with fn:substring-before

<url>{substring-before(data($y/link[1]/#href),'&')}</url>
The error I get when trying to run this is
No closing ';' found for entity or character reference
Anybody have any idea what's causing this error?
In XQuery an ampersand within a string literal (and in certain other contexts) needs to be escaped as &, just as it would be in XML.
Michael Kay is correct. The "&" is illegal by itself in XML. It is always to be accompanied by an entity. Examples include & < >, etc.
If you think that your search won't work because you are searching for "&" instead of "&", that is not proper thinking. As a human, try to translate in your head that "&" really looks like "&" to the XML parser. Doing this will work:
<url>{substring-before(data($y/link[1]/#href),'&amp')}</url>

Resources