Skip to content

Commit 31416f9

Browse files
committed
BAEL-5732 Moved from spring-code-4 module to core-java-string-operation-9
1 parent a982263 commit 31416f9

File tree

6 files changed

+75
-70
lines changed

6 files changed

+75
-70
lines changed

core-java-modules/core-java-string-operations-9/pom.xml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,27 @@
4444
<artifactId>commons-collections4</artifactId>
4545
<version>${apache.commons.collection.version}</version>
4646
</dependency>
47+
<dependency>
48+
<groupId>org.apache.commons</groupId>
49+
<artifactId>commons-text</artifactId>
50+
<version>${commons-text.version}</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.unbescape</groupId>
54+
<artifactId>unbescape</artifactId>
55+
<version>1.1.6.RELEASE</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.jsoup</groupId>
59+
<artifactId>jsoup</artifactId>
60+
<version>1.14.3</version>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.springframework</groupId>
64+
<artifactId>spring-web</artifactId>
65+
<version>6.1.6</version>
66+
</dependency>
67+
4768
</dependencies>
4869

4970
<build>
@@ -67,4 +88,4 @@
6788
<icu4j.version>74.1</icu4j.version>
6889
</properties>
6990

70-
</project>
91+
</project>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.baeldung.unescapehtml;
2+
3+
4+
import org.apache.commons.text.StringEscapeUtils;
5+
import org.jsoup.nodes.Entities;
6+
import org.junit.Assert;
7+
import org.junit.jupiter.api.Test;
8+
import org.springframework.web.util.HtmlUtils;
9+
import org.unbescape.html.HtmlEscape;
10+
11+
public class HtmlUnescapeUnitTest {
12+
@Test
13+
public void givenAStringsWithHTMLCharacters_whenConvertedWithApacheCommons_thenUnescape(){
14+
String expectedQuote = "\"Hello\" Baeldung";
15+
String escapedQuote = "&quot;Hello&quot; Baeldung";
16+
Assert.assertEquals(expectedQuote, StringEscapeUtils.unescapeHtml4(escapedQuote));
17+
18+
String escapedStringsWithHtmlSymbol = "&lt;p&gt;&lt;strong&gt;Test sentence in bold type.&lt;/strong&gt;&lt;/p&gt;";
19+
String expectedStringsWithHtmlSymbol = "<p><strong>Test sentence in bold type.</strong></p>";
20+
Assert.assertEquals(expectedStringsWithHtmlSymbol, StringEscapeUtils.unescapeHtml4(escapedStringsWithHtmlSymbol));
21+
}
22+
@Test
23+
public void givenAStringsWithHTMLCharacters_whenConvertedWithSpringHtmlUtil_thenUnescape() {
24+
String expectedQuote = "\"Code smells\" -Martin Fowler";
25+
String escapedQuote = "&quot;Code smells&quot; -Martin Fowler";
26+
Assert.assertEquals(expectedQuote, HtmlUtils.htmlUnescape(escapedQuote));
27+
28+
String escapedStringsWithHtmlSymbol = "&lt;p&gt;Loren Ipsum is a popular paragraph.&lt;/p&gt;";
29+
String expectedStringsWithHtmlSymbol = "<p>Loren Ipsum is a popular paragraph.</p>";
30+
Assert.assertEquals(expectedStringsWithHtmlSymbol, HtmlUtils.htmlUnescape(escapedStringsWithHtmlSymbol));
31+
}
32+
33+
@Test
34+
public void givenAStringsWithHTMLCharacters_whenConvertedWithUnbescape_thenUnescape() {
35+
String expectedQuote = "\"Carpe diem\" -Horace";
36+
String escapedQuote = "&quot;Carpe diem&quot; -Horace";
37+
Assert.assertEquals(expectedQuote, HtmlEscape.unescapeHtml(escapedQuote));
38+
39+
String escapedStringsWithHtmlSymbol = "&lt;p&gt;&lt;em&gt;Pizza is a famous Italian food. Duh.&lt;/em&gt;&lt;/p&gt;";
40+
String expectedStringsWithHtmlSymbol = "<p><em>Pizza is a famous Italian food. Duh.</em></p>";
41+
Assert.assertEquals(expectedStringsWithHtmlSymbol, HtmlEscape.unescapeHtml(escapedStringsWithHtmlSymbol));
42+
}
43+
@Test
44+
public void givenAStringsWithHTMLCharacters_whenConvertedWithJsoup_thenUnescape() {
45+
String expectedQuote = "\"Jsoup\" is another strong library";
46+
String escapedQuote = "&quot;Jsoup&quot; is another strong library";
47+
Assert.assertEquals(expectedQuote, Entities.unescape(escapedQuote));
48+
49+
String escapedStringsWithHtmlSymbol = "&lt;p&gt;It simplifies working with real-world &lt;strong&gt;HTML&lt;/strong&gt; and &lt;strong&gt;XML&lt;/strong&gt;&lt;/p&gt;";
50+
String expectedStringsWithHtmlSymbol = "<p>It simplifies working with real-world <strong>HTML</strong> and <strong>XML</strong></p>";
51+
Assert.assertEquals(expectedStringsWithHtmlSymbol, Entities.unescape(escapedStringsWithHtmlSymbol));
52+
}
53+
}

spring-core-4/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ This module contains articles about core Spring functionality
77
- [Creating Spring Beans Through Factory Methods](https://www.baeldung.com/spring-beans-factory-methods)
88
- [Spring BeanPostProcessor](https://www.baeldung.com/spring-beanpostprocessor)
99
- [Escape HTML Symbols in Java](https://www.baeldung.com/java-escape-html-symbols)
10-
- [Unescape HTML Symbols in Java](https://www.baeldung.com/unescape-html-characters-in-java)
1110
- More articles: [[<-- prev]](/spring-core-3)

spring-core-4/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@
7070
<artifactId>commons-text</artifactId>
7171
<version>${commons-text.version}</version>
7272
</dependency>
73-
<dependency>
74-
<groupId>org.unbescape</groupId>
75-
<artifactId>unbescape</artifactId>
76-
<version>1.1.6.RELEASE</version>
77-
</dependency>
7873
</dependencies>
7974

8075
<properties>

spring-core-4/src/main/java/com/baeldung/Unescapehtml/HtmlUnescapeUtils.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

spring-core-4/src/test/java/com/baeldung/unescapehtml/HtmlUnescapeUtilsTest.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)