Remove stringutils and add simple escaper (#34)
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -52,11 +52,6 @@
|
||||
<version>1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package j2html.attributes;
|
||||
|
||||
import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;
|
||||
|
||||
import j2html.utils.SimpleEscaper;
|
||||
|
||||
public class Attribute {
|
||||
private String name;
|
||||
@@ -8,7 +9,7 @@ public class Attribute {
|
||||
|
||||
public Attribute(String name, String value) {
|
||||
this.name = name;
|
||||
this.value = escapeHtml4(value);
|
||||
this.value = SimpleEscaper.escape(value);
|
||||
}
|
||||
|
||||
public Attribute(String name) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package j2html.tags;
|
||||
|
||||
import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;
|
||||
import j2html.utils.SimpleEscaper;
|
||||
|
||||
public class Text extends DomContent {
|
||||
|
||||
@@ -12,7 +12,7 @@ public class Text extends DomContent {
|
||||
|
||||
@Override
|
||||
public String render() {
|
||||
return escapeHtml4(text);
|
||||
return SimpleEscaper.escape(text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
28
src/main/java/j2html/utils/SimpleEscaper.java
Normal file
28
src/main/java/j2html/utils/SimpleEscaper.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package j2html.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SimpleEscaper {
|
||||
|
||||
private static Map<Character, String> map = new HashMap<Character, String>() {{
|
||||
put('&', "&");
|
||||
put('<', "<");
|
||||
put('>', ">");
|
||||
put('"', """);
|
||||
put('\'', "'");
|
||||
}};
|
||||
|
||||
public static String escape(String s) {
|
||||
if(s == null) {
|
||||
return null;
|
||||
}
|
||||
String escapedString = "";
|
||||
for(char c : s.toCharArray()) {
|
||||
String escaped = map.get(c);
|
||||
escapedString += escaped != null ? escaped : c;
|
||||
}
|
||||
return escapedString;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user