|
| 1 | +package org.springframework.web.util; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.DisplayName; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | + |
| 6 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 7 | + |
| 8 | +class HtmlCharacterEntityDecoderTest { |
| 9 | + |
| 10 | + @Test |
| 11 | + @DisplayName("Should correctly unescape Unicode supplementary characters") |
| 12 | + void unescapeHandlesSupplementaryCharactersCorrectly() { |
| 13 | + // Arrange: Prepare test cases with the 'grinning face' emoji (😀, U+1F600). |
| 14 | + String expectedCharacter = "😀"; |
| 15 | + String decimalEntity = "😀"; |
| 16 | + String hexEntity = "😀"; |
| 17 | + |
| 18 | + // Act: Call the HtmlUtils.htmlUnescape method to get the actual results. |
| 19 | + String actualResultFromDecimal = HtmlUtils.htmlUnescape(decimalEntity); |
| 20 | + String actualResultFromHex = HtmlUtils.htmlUnescape(hexEntity); |
| 21 | + |
| 22 | + // Assert: Verify that the actual results match the expected character. |
| 23 | + assertEquals(expectedCharacter, actualResultFromDecimal, "Decimal entity was not converted correctly."); |
| 24 | + assertEquals(expectedCharacter, actualResultFromHex, "Hexadecimal entity was not converted correctly."); |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + @DisplayName("Should correctly unescape basic and named HTML entities") |
| 29 | + void unescapeHandlesBasicEntities() { |
| 30 | + // Arrange |
| 31 | + String input = "<p>Tom & Jerry's "Show"</p>"; |
| 32 | + String expectedOutput = "<p>Tom & Jerry's \"Show\"</p>"; |
| 33 | + |
| 34 | + // Act |
| 35 | + String actualOutput = HtmlUtils.htmlUnescape(input); |
| 36 | + |
| 37 | + // Assert |
| 38 | + assertEquals(expectedOutput, actualOutput, "Basic HTML entities were not unescaped correctly."); |
| 39 | + } |
| 40 | + |
| 41 | +} |
| 42 | + |
0 commit comments