Skip to content

Commit 9982b4c

Browse files
committed
Add BS and VT char escape sequences to JavaScriptUtils
Issue: SPR-9983
1 parent e4f1f68 commit 9982b4c

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

spring-web/src/main/java/org/springframework/web/util/JavaScriptUtils.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,21 +21,21 @@
2121
* Escapes based on the JavaScript 1.5 recommendation.
2222
*
2323
* <p>Reference:
24-
* <a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Literals#String_Literals">
25-
* Core JavaScript 1.5 Guide
26-
* </a>
24+
* <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Values,_variables,_and_literals#String_literals">
25+
* JavaScript Guide</a> on Mozilla Developer Network.
2726
*
2827
* @author Juergen Hoeller
2928
* @author Rob Harrop
29+
* @author Rossen Stoyanchev
3030
* @since 1.1.1
3131
*/
3232
public class JavaScriptUtils {
3333

3434
/**
35-
* Turn special characters into escaped characters conforming to JavaScript.
36-
* Handles complete character set defined in HTML 4.01 recommendation.
35+
* Turn JavaScript special characters into escaped characters.
36+
*
3737
* @param input the input string
38-
* @return the escaped string
38+
* @return the string with escaped characters
3939
*/
4040
public static String javaScriptEscape(String input) {
4141
if (input == null) {
@@ -73,6 +73,13 @@ else if (c == '\r') {
7373
else if (c == '\f') {
7474
filtered.append("\\f");
7575
}
76+
else if (c == '\b') {
77+
filtered.append("\\b");
78+
}
79+
// No '\v' in Java, use octal value for VT ascii char
80+
else if (c == '\013') {
81+
filtered.append("\\v");
82+
}
7683
else {
7784
filtered.append(c);
7885
}

0 commit comments

Comments
 (0)