Added JS escaping for newline, linefeed, return, tab and backspace. Closes #1
This commit is contained in:
parent
a0ebfe2566
commit
0d14c27032
2 changed files with 10 additions and 0 deletions
|
@ -195,6 +195,11 @@ public final class RenderUtils {
|
|||
case '"' -> sb.append("\\\"");
|
||||
case '\\' -> sb.append("\\\\");
|
||||
case '/' -> sb.append("\\/");
|
||||
case '\b' -> sb.append("\\b");
|
||||
case '\n' -> sb.append(("\\n"));
|
||||
case '\t' -> sb.append("\\t");
|
||||
case '\f' -> sb.append("\\f");
|
||||
case '\r' -> sb.append("\\r");
|
||||
default -> sb.append(c);
|
||||
}
|
||||
}
|
||||
|
@ -597,4 +602,5 @@ public final class RenderUtils {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -55,6 +55,10 @@ class TestEncode {
|
|||
t.setAttribute(TestCase.FOO, "'\"\\/");
|
||||
assertThat(t.getContent()).isEqualTo("\\'\\\"\\\\\\/");
|
||||
|
||||
t = TemplateFactory.TXT.get("encodeJs");
|
||||
t.setAttribute(TestCase.FOO, "This is\f\b a\r\n\ttest");
|
||||
assertThat(t.getContent()).isEqualTo("This is\\f\\b a\\r\\n\\ttest");
|
||||
|
||||
t = TemplateFactory.HTML.get("encodeJs");
|
||||
t.setAttribute(TestCase.FOO, '"' + TestCase.SAMPLE_TEXT + '"');
|
||||
assertThat(t.getContent()).as("with unicode")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue