|
1 | 1 | /* |
2 | | - * Copyright 2002-2008 the original author or authors. |
| 2 | + * Copyright 2002-2013 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
21 | 21 | * Escapes based on the JavaScript 1.5 recommendation. |
22 | 22 | * |
23 | 23 | * <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. |
27 | 26 | * |
28 | 27 | * @author Juergen Hoeller |
29 | 28 | * @author Rob Harrop |
| 29 | + * @author Rossen Stoyanchev |
30 | 30 | * @since 1.1.1 |
31 | 31 | */ |
32 | 32 | public class JavaScriptUtils { |
33 | 33 |
|
34 | 34 | /** |
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 | + * |
37 | 37 | * @param input the input string |
38 | | - * @return the escaped string |
| 38 | + * @return the string with escaped characters |
39 | 39 | */ |
40 | 40 | public static String javaScriptEscape(String input) { |
41 | 41 | if (input == null) { |
@@ -73,6 +73,27 @@ else if (c == '\r') { |
73 | 73 | else if (c == '\f') { |
74 | 74 | filtered.append("\\f"); |
75 | 75 | } |
| 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 | + } |
| 83 | + else if (c == '<') { |
| 84 | + filtered.append("\\u003C"); |
| 85 | + } |
| 86 | + else if (c == '>') { |
| 87 | + filtered.append("\\u003E"); |
| 88 | + } |
| 89 | + // Unicode for PS (line terminator in ECMA-262) |
| 90 | + else if (c == '\u2028') { |
| 91 | + filtered.append("\\u2028"); |
| 92 | + } |
| 93 | + // Unicode for LS (line terminator in ECMA-262) |
| 94 | + else if (c == '\u2029') { |
| 95 | + filtered.append("\\u2029"); |
| 96 | + } |
76 | 97 | else { |
77 | 98 | filtered.append(c); |
78 | 99 | } |
|
0 commit comments