diff --git a/spring-web/src/test/java/org/springframework/web/util/HtmlCharacterEntityDecoderTests.java b/spring-web/src/test/java/org/springframework/web/util/HtmlCharacterEntityDecoderTests.java deleted file mode 100644 index 8aa45a08a66..00000000000 --- a/spring-web/src/test/java/org/springframework/web/util/HtmlCharacterEntityDecoderTests.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 = "
Tom & Jerry's \"Show\"
"; - String actualOutput = HtmlUtils.htmlUnescape(input); - assertThat(actualOutput).as("Basic HTML entities were not unescaped correctly.").isEqualTo(expectedOutput); - } - -} diff --git a/spring-web/src/test/java/org/springframework/web/util/HtmlUtilsTests.java b/spring-web/src/test/java/org/springframework/web/util/HtmlUtilsTests.java index 0c0e03fe065..c9651d236fb 100644 --- a/spring-web/src/test/java/org/springframework/web/util/HtmlUtilsTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/HtmlUtilsTests.java @@ -21,6 +21,8 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; /** + * Tests for {@link HtmlUtils}. + * * @author Alef Arendsen * @author Martin Kersten * @author Rick Evans @@ -28,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat; class HtmlUtilsTests { @Test - void testHtmlEscape() { + void htmlEscape() { String unescaped = "\"This is a quote'"; String escaped = HtmlUtils.htmlEscape(unescaped); assertThat(escaped).isEqualTo(""This is a quote'"); @@ -39,14 +41,7 @@ class HtmlUtilsTests { } @Test - void testHtmlUnescape() { - String escaped = ""This is a quote'"; - String unescaped = HtmlUtils.htmlUnescape(escaped); - assertThat(unescaped).isEqualTo("\"This is a quote'"); - } - - @Test - void testEncodeIntoHtmlCharacterSet() { + void htmlEscapeIntoHtmlCharacterSet() { assertThat(HtmlUtils.htmlEscape("")).as("An empty string should be converted to an empty string").isEmpty(); assertThat(HtmlUtils.htmlEscape("A sentence containing no special characters.")).as("A string containing no special characters should not be affected").isEqualTo("A sentence containing no special characters."); @@ -60,12 +55,11 @@ class HtmlUtilsTests { assertThat(HtmlUtils.htmlEscapeDecimal("" + (char) 977)).as("The special character 977 should be encoded to 'ϑ'").isEqualTo("ϑ"); } - // SPR-9293 - @Test - void testEncodeIntoHtmlCharacterSetFromUtf8() { + @Test // SPR-9293 + void htmlEscapeIntoHtmlCharacterSetFromUtf8() { String utf8 = ("UTF-8"); - assertThat(HtmlUtils.htmlEscape("", utf8)).as("An empty string should be converted to an empty string") - .isEmpty(); + + assertThat(HtmlUtils.htmlEscape("", utf8)).as("An empty string should be converted to an empty string").isEmpty(); assertThat(HtmlUtils.htmlEscape("A sentence containing no special characters.")).as("A string containing no special characters should not be affected").isEqualTo("A sentence containing no special characters."); assertThat(HtmlUtils.htmlEscape("< >", utf8)).as("'< >' should be encoded to '< >'").isEqualTo("< >"); @@ -75,7 +69,38 @@ class HtmlUtilsTests { } @Test - void testDecodeFromHtmlCharacterSet() { + void htmlUnescape() { + String escaped = ""This is a quote'"; + String unescaped = HtmlUtils.htmlUnescape(escaped); + assertThat(unescaped).isEqualTo("\"This is a quote'"); + } + + @Test + void htmlUnescapeHandlesSupplementaryCharactersAsDecimal() { + String expectedCharacter = "😀"; + String decimalEntity = "😀"; + String actualResultFromDecimal = HtmlUtils.htmlUnescape(decimalEntity); + assertThat(actualResultFromDecimal).as("Decimal entity was not converted correctly.").isEqualTo(expectedCharacter); + } + + @Test + void htmlUnescapeHandlesSupplementaryCharactersAsHexadecimal() { + String expectedCharacter = "😀"; + String hexEntity = "😀"; + String actualResultFromHex = HtmlUtils.htmlUnescape(hexEntity); + assertThat(actualResultFromHex).as("Hexadecimal entity was not converted correctly.").isEqualTo(expectedCharacter); + } + + @Test + void htmlUnescapeHandlesBasicEntities() { + String input = "<p>Tom & Jerry's "Show"</p>"; + String expectedOutput = "Tom & Jerry's \"Show\"
"; + String actualOutput = HtmlUtils.htmlUnescape(input); + assertThat(actualOutput).as("Basic HTML entities were not unescaped correctly.").isEqualTo(expectedOutput); + } + + @Test + void htmlUnescapeFromHtmlCharacterSet() { assertThat(HtmlUtils.htmlUnescape("")).as("An empty string should be converted to an empty string").isEmpty(); assertThat(HtmlUtils.htmlUnescape("This is a sentence containing no special characters.")).as("A string containing no special characters should not be affected").isEqualTo("This is a sentence containing no special characters.");