mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Refine JavaScriptUtils#javaScriptEscape
Closes gh-36795
This commit is contained in:
committed by
Brian Clozel
parent
7add5243b9
commit
a1826b725c
@@ -27,6 +27,7 @@ package org.springframework.web.util;
|
||||
* @author Juergen Hoeller
|
||||
* @author Rob Harrop
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Sebastien Deleuze
|
||||
* @since 1.1.1
|
||||
*/
|
||||
public abstract class JavaScriptUtils {
|
||||
@@ -89,6 +90,12 @@ public abstract class JavaScriptUtils {
|
||||
else if (c == '\u2029') {
|
||||
filtered.append("\\u2029");
|
||||
}
|
||||
else if (c == '`') {
|
||||
filtered.append("\\u0060");
|
||||
}
|
||||
else if (c == '$') {
|
||||
filtered.append("\\u0024");
|
||||
}
|
||||
else {
|
||||
filtered.append(c);
|
||||
}
|
||||
|
||||
@@ -62,4 +62,14 @@ class JavaScriptUtilsTests {
|
||||
assertThat(JavaScriptUtils.javaScriptEscape("<>")).isEqualTo("\\u003C\\u003E");
|
||||
}
|
||||
|
||||
@Test
|
||||
void escapeBacktick() {
|
||||
assertThat(JavaScriptUtils.javaScriptEscape("`")).isEqualTo("\\u0060");
|
||||
}
|
||||
|
||||
@Test
|
||||
void escapeDollar() {
|
||||
assertThat(JavaScriptUtils.javaScriptEscape("$")).isEqualTo("\\u0024");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user