I'm trying to compare the values of two strings in a jsp file. Both of these strings contain an apostrophe '
. These strings some from different sources.
When I directly compare the two strings like this:
<c:if test="${ fn:toLowerCase(colorInfo.value.name) eq fn:toLowerCase(colorName) }">
hello!
</c:if>
the comparison returns a false. When I print out the two values, however, I see
Mike's Green
Mike's Green
in a previous step, these strings are trimmed to this is not a whitespace issue. For whatever reason, when stored as variables, one of these two is stored with an xml escaped apostrophe
'
To prove this, I modified the comparison to the following:
<c:set var="apostrophe" value="'" />
<%-- I'm multilining this purely for readability on SO, it's 1 line in the code --%>
<c:if test="${
fn:replace(fn:toLowerCase(colorInfo.value.name), ''', apostrophe)
eq
fn:replace(fn:toLowerCase(colorName), ''', apostrophe)
}">
hello!
</c:if>
This comparison returns true. Therefore, one of the two strings has a literal xml escape'd version of apostrophe while being stored.
Is there a more efficient way to escape any xml strings within a stored jsp variable? This is a very ugly way of doing the comparison, and it's not easily scalable as if future strings have other characters that are escaping improperly, then I will need to add more code to this logic.