Fix HtmlUtils unescape for supplementary chars

See gh-35477

Signed-off-by: potato <65760583+juntae6942@users.noreply.github.com>
This commit is contained in:
potato
2025-09-13 23:15:49 +09:00
committed by Brian Clozel
parent 3b6be3d4d3
commit 47de8b05e6
2 changed files with 46 additions and 1 deletions
@@ -0,0 +1,42 @@
package org.springframework.web.util;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class HtmlCharacterEntityDecoderTest {
@Test
@DisplayName("Should correctly unescape Unicode supplementary characters")
void unescapeHandlesSupplementaryCharactersCorrectly() {
// Arrange: Prepare test cases with the 'grinning face' emoji (😀, U+1F600).
String expectedCharacter = "😀";
String decimalEntity = "&#128512;";
String hexEntity = "&#x1F600;";
// Act: Call the HtmlUtils.htmlUnescape method to get the actual results.
String actualResultFromDecimal = HtmlUtils.htmlUnescape(decimalEntity);
String actualResultFromHex = HtmlUtils.htmlUnescape(hexEntity);
// Assert: Verify that the actual results match the expected character.
assertEquals(expectedCharacter, actualResultFromDecimal, "Decimal entity was not converted correctly.");
assertEquals(expectedCharacter, actualResultFromHex, "Hexadecimal entity was not converted correctly.");
}
@Test
@DisplayName("Should correctly unescape basic and named HTML entities")
void unescapeHandlesBasicEntities() {
// Arrange
String input = "&lt;p&gt;Tom &amp; Jerry&#39;s &quot;Show&quot;&lt;/p&gt;";
String expectedOutput = "<p>Tom & Jerry's \"Show\"</p>";
// Act
String actualOutput = HtmlUtils.htmlUnescape(input);
// Assert
assertEquals(expectedOutput, actualOutput, "Basic HTML entities were not unescaped correctly.");
}
}