This commit is contained in:
potato🥔 2025-10-07 23:10:36 +03:00 committed by GitHub
commit ca6c8e6c33
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 1 deletions

View File

@ -124,7 +124,10 @@ class HtmlCharacterEntityDecoder {
int value = (!isHexNumberedReference ?
Integer.parseInt(getReferenceSubstring(2)) :
Integer.parseInt(getReferenceSubstring(3), 16));
this.decodedMessage.append((char) value);
if (value > Character.MAX_CODE_POINT) {
return false;
}
this.decodedMessage.appendCodePoint(value);
return true;
}
catch (NumberFormatException ex) {

View File

@ -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 = "😀";
String hexEntity = "😀";
// 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 = "<p>Tom & Jerry's "Show"</p>";
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.");
}
}