Escape Attribute on render instead of in constructor. Fixes #160 (#162)

Also initialize EscapeUtil StringBuilder with input length to avoid growing copying.
This commit is contained in:
lambdaupb
2020-09-24 08:50:01 +02:00
committed by GitHub
parent 94ad6e29a3
commit 7d98d4f2bd
2 changed files with 5 additions and 5 deletions

View File

@@ -10,7 +10,7 @@ public class Attribute implements Renderable {
public Attribute(String name, String value) {
this.name = name;
this.value = Config.textEscaper.escape(value);
this.value = value;
}
public Attribute(String name) {
@@ -23,12 +23,12 @@ public class Attribute implements Renderable {
if (name == null) {
return;
}
writer.append(" ");
writer.append(' ');
writer.append(name);
if (value != null) {
writer.append("=\"");
writer.append(value);
writer.append("\"");
writer.append(Config.textEscaper.escape(value));
writer.append('"');
}
}

View File

@@ -6,7 +6,7 @@ public class EscapeUtil {
if (s == null) {
return null;
}
StringBuilder escapedText = new StringBuilder();
StringBuilder escapedText = new StringBuilder(s.length()+16);
char currentChar;
for (int i = 0; i < s.length(); i++) {
currentChar = s.charAt(i);