Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ private boolean processNumberedReference() {
int value = (!isHexNumberedReference ?
Integer.parseInt(getReferenceSubstring(2)) :
Integer.parseInt(getReferenceSubstring(3), 16));
if (value < 0 || value > Character.MAX_CODE_POINT) {
if (value < 0 || value > Character.MAX_CODE_POINT ||
(value >= Character.MIN_SURROGATE && value <= Character.MAX_SURROGATE)) {
return false;
}
this.decodedMessage.appendCodePoint(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ void htmlUnescapeHandlesSupplementaryCharactersAsHexadecimal() {
assertThat(actualResultFromHex).as("Hexadecimal entity was not converted correctly.").isEqualTo(expectedCharacter);
}

@Test
void htmlUnescapeLeavesSurrogateReferencesUnchanged() {
assertThat(HtmlUtils.htmlUnescape("x&#55296;y")).isEqualTo("x&#55296;y");
assertThat(HtmlUtils.htmlUnescape("x&#xDFFF;y")).isEqualTo("x&#xDFFF;y");
assertThat(HtmlUtils.htmlUnescape("x&#xD7FF;y")).isEqualTo("x\uD7FFy");
assertThat(HtmlUtils.htmlUnescape("x&#xE000;y")).isEqualTo("x\uE000y");
}

@Test
void htmlUnescapeHandlesBasicEntities() {
String input = "&lt;p&gt;Tom &amp; Jerry&#39;s &quot;Show&quot;&lt;/p&gt;";
Expand Down