Skip to content
Browse files

Java: escape '/' in strings after a '<' character

  • Loading branch information...
1 parent 82b0ac8 commit 454fafda183b5cdc0338da34c74e7a69eb8c8283 @mernen mernen committed Nov 1, 2010
Showing with 12 additions and 2 deletions.
  1. +12 −2 java/src/json/ext/StringEncoder.java
View
14 java/src/json/ext/StringEncoder.java
@@ -40,14 +40,17 @@
void encode(ByteList src, ByteList out) {
init(src, out);
append('"');
+ int lastChar = -1;
while (hasNext()) {
- handleChar(readUtf8Char());
+ int newChar = readUtf8Char();
+ handleChar(newChar, lastChar);
+ lastChar = newChar;
}
quoteStop(pos);
append('"');
}
- private void handleChar(int c) {
+ private void handleChar(int c, int lastChar) {
switch (c) {
case '"':
case '\\':
@@ -68,6 +71,13 @@ private void handleChar(int c) {
case '\b':
escapeChar('b');
break;
+ case '/':
+ if (lastChar == '<') {
+ escapeChar('/');
+ } else {
+ quoteStart();
+ }
+ break;
default:
if (c >= 0x20 && c <= 0x7f ||
(c >= 0x80 && !asciiOnly)) {

0 comments on commit 454fafd

Please sign in to comment.
Something went wrong with that request. Please try again.