Re-enabling the ' (apostrophe) escaping with valid JSON escaping.

This commit is contained in:
Joel Leitch 2009-10-07 03:48:29 +00:00
parent 536a968b32
commit c892738fbb
2 changed files with 4 additions and 9 deletions

View File

@ -54,9 +54,7 @@ class Escaper {
htmlEscapeSet.add('>');
htmlEscapeSet.add('&');
htmlEscapeSet.add('=');
// Removing ' for now since it is a valid character in JSON, but not javascript
// When enabling this, remember to enable the test EscaperTest.disable_testSingleQuoteEscaping
// htmlEscapeSet.add('\'');
htmlEscapeSet.add('\'');
// htmlEscapeSet.add('/'); -- Removing slash for now since it causes some incompatibilities
HTML_ESCAPE_CHARS = Collections.unmodifiableSet(htmlEscapeSet);
}
@ -114,10 +112,7 @@ class Escaper {
out.append("\\/");
break;
case '"':
out.append('\\').append((char) codePoint);
break;
case '\'':
out.append('\\').append((char) codePoint);
out.append("\\\"");
break;
default:
appendHexJavaScriptRepresentation(codePoint, out);

View File

@ -65,10 +65,10 @@ public class EscaperTest extends TestCase {
assertEquals("123\\\"456", escapedString);
}
public void disable_testSingleQuoteEscaping() throws Exception {
public void testSingleQuoteEscaping() throws Exception {
String containsQuote = "123'456";
String escapedString = escapeHtmlChar.escapeJsonString(containsQuote);
assertEquals("123\\'456", escapedString);
assertEquals("123\\u0027456", escapedString);
}
public void testLineSeparatorEscaping() throws Exception {