2 changed files with 53 additions and 42 deletions
@ -1,42 +0,0 @@
@@ -1,42 +0,0 @@
|
||||
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."); |
||||
} |
||||
|
||||
} |
||||
|
||||
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
/* |
||||
* Copyright 2002-present the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.web.util; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
|
||||
/** |
||||
* Tests for {@link HtmlCharacterEntityDecoder}. |
||||
*/ |
||||
class HtmlCharacterEntityDecoderTests { |
||||
|
||||
@Test |
||||
void unescapeHandlesSupplementaryCharactersAsDecimal() { |
||||
String expectedCharacter = "😀"; |
||||
String decimalEntity = "😀"; |
||||
String actualResultFromDecimal = HtmlUtils.htmlUnescape(decimalEntity); |
||||
assertThat(actualResultFromDecimal).as("Decimal entity was not converted correctly.").isEqualTo(expectedCharacter); |
||||
} |
||||
|
||||
@Test |
||||
void unescapeHandlesSupplementaryCharactersAsHexadecimal() { |
||||
String expectedCharacter = "😀"; |
||||
String hexEntity = "😀"; |
||||
String actualResultFromHex = HtmlUtils.htmlUnescape(hexEntity); |
||||
assertThat(actualResultFromHex).as("Hexadecimal entity was not converted correctly.").isEqualTo(expectedCharacter); |
||||
} |
||||
|
||||
@Test |
||||
void unescapeHandlesBasicEntities() { |
||||
String input = "<p>Tom & Jerry's "Show"</p>"; |
||||
String expectedOutput = "<p>Tom & Jerry's \"Show\"</p>"; |
||||
String actualOutput = HtmlUtils.htmlUnescape(input); |
||||
assertThat(actualOutput).as("Basic HTML entities were not unescaped correctly.").isEqualTo(expectedOutput); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue