Skip to content

Commit 030dace

Browse files
committed
Polishing contribution
Closes gh-35477
1 parent 5af1c9b commit 030dace

File tree

2 files changed

+53
-42
lines changed

2 files changed

+53
-42
lines changed

spring-web/src/test/java/org/springframework/web/util/HtmlCharacterEntityDecoderTest.java

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2002-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.web.util;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import static org.assertj.core.api.Assertions.assertThat;
22+
23+
24+
/**
25+
* Tests for {@link HtmlCharacterEntityDecoder}.
26+
*/
27+
class HtmlCharacterEntityDecoderTests {
28+
29+
@Test
30+
void unescapeHandlesSupplementaryCharactersAsDecimal() {
31+
String expectedCharacter = "😀";
32+
String decimalEntity = "😀";
33+
String actualResultFromDecimal = HtmlUtils.htmlUnescape(decimalEntity);
34+
assertThat(actualResultFromDecimal).as("Decimal entity was not converted correctly.").isEqualTo(expectedCharacter);
35+
}
36+
37+
@Test
38+
void unescapeHandlesSupplementaryCharactersAsHexadecimal() {
39+
String expectedCharacter = "😀";
40+
String hexEntity = "😀";
41+
String actualResultFromHex = HtmlUtils.htmlUnescape(hexEntity);
42+
assertThat(actualResultFromHex).as("Hexadecimal entity was not converted correctly.").isEqualTo(expectedCharacter);
43+
}
44+
45+
@Test
46+
void unescapeHandlesBasicEntities() {
47+
String input = "<p>Tom & Jerry's "Show"</p>";
48+
String expectedOutput = "<p>Tom & Jerry's \"Show\"</p>";
49+
String actualOutput = HtmlUtils.htmlUnescape(input);
50+
assertThat(actualOutput).as("Basic HTML entities were not unescaped correctly.").isEqualTo(expectedOutput);
51+
}
52+
53+
}

0 commit comments

Comments
 (0)