318308 Correct quoting of unicode control characters
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2057 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
3b5c2dd465
commit
849b77925c
|
@ -10,6 +10,7 @@ jetty-7.1.5-SNAPSHOT
|
|||
+ 317019 Date HTTP header not sent for HTTP/1.0 requests
|
||||
+ 317759 Allow roles and constraints to be added after init
|
||||
+ 317906 OPTIONS correctly handles TRACE
|
||||
+ 318308 Correct quoting of unicode control characters
|
||||
+ JETTY-1237 Save local/remote address to be available after close
|
||||
|
||||
jetty-7.1.4.v20100610
|
||||
|
|
|
@ -322,82 +322,47 @@ public class QuotedStringTokenizer
|
|||
{
|
||||
buf.append('"');
|
||||
|
||||
int i=0;
|
||||
loop:
|
||||
for (;i<s.length();i++)
|
||||
{
|
||||
char c = s.charAt(i);
|
||||
switch(c)
|
||||
{
|
||||
case '"':
|
||||
buf.append(s,0,i);
|
||||
buf.append("\\\"");
|
||||
break loop;
|
||||
case '\\':
|
||||
buf.append(s,0,i);
|
||||
buf.append("\\\\");
|
||||
break loop;
|
||||
case '\n':
|
||||
buf.append(s,0,i);
|
||||
buf.append("\\n");
|
||||
break loop;
|
||||
case '\r':
|
||||
buf.append(s,0,i);
|
||||
buf.append("\\r");
|
||||
break loop;
|
||||
case '\t':
|
||||
buf.append(s,0,i);
|
||||
buf.append("\\t");
|
||||
break loop;
|
||||
case '\f':
|
||||
buf.append(s,0,i);
|
||||
buf.append("\\f");
|
||||
break loop;
|
||||
case '\b':
|
||||
buf.append(s,0,i);
|
||||
buf.append("\\b");
|
||||
break loop;
|
||||
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (i==s.length())
|
||||
buf.append(s);
|
||||
else
|
||||
for (int i=0;i<s.length();i++)
|
||||
{
|
||||
i++;
|
||||
for (;i<s.length();i++)
|
||||
char c = s.charAt(i);
|
||||
switch(c)
|
||||
{
|
||||
char c = s.charAt(i);
|
||||
switch(c)
|
||||
{
|
||||
case '"':
|
||||
buf.append("\\\"");
|
||||
continue;
|
||||
case '\\':
|
||||
buf.append("\\\\");
|
||||
continue;
|
||||
case '\n':
|
||||
buf.append("\\n");
|
||||
continue;
|
||||
case '\r':
|
||||
buf.append("\\r");
|
||||
continue;
|
||||
case '\t':
|
||||
buf.append("\\t");
|
||||
continue;
|
||||
case '\f':
|
||||
buf.append("\\f");
|
||||
continue;
|
||||
case '\b':
|
||||
buf.append("\\b");
|
||||
continue;
|
||||
case '"':
|
||||
buf.append("\\\"");
|
||||
continue;
|
||||
case '\\':
|
||||
buf.append("\\\\");
|
||||
continue;
|
||||
case '\n':
|
||||
buf.append("\\n");
|
||||
continue;
|
||||
case '\r':
|
||||
buf.append("\\r");
|
||||
continue;
|
||||
case '\t':
|
||||
buf.append("\\t");
|
||||
continue;
|
||||
case '\f':
|
||||
buf.append("\\f");
|
||||
continue;
|
||||
case '\b':
|
||||
buf.append("\\b");
|
||||
continue;
|
||||
|
||||
default:
|
||||
default:
|
||||
if (c<0x10)
|
||||
{
|
||||
buf.append("\\u000");
|
||||
buf.append(Integer.toString(c,16));
|
||||
}
|
||||
else if (c<=0x1f)
|
||||
{
|
||||
buf.append("\\u00");
|
||||
buf.append(Integer.toString(c,16));
|
||||
}
|
||||
else
|
||||
buf.append(c);
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -408,10 +373,7 @@ public class QuotedStringTokenizer
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Quote a string into a StringBuffer only if needed.
|
||||
* Quotes are forced if any delim characters are present.
|
||||
|
@ -489,6 +451,15 @@ public class QuotedStringTokenizer
|
|||
case 'b':
|
||||
b.append('\b');
|
||||
break;
|
||||
case '\\':
|
||||
b.append('\\');
|
||||
break;
|
||||
case '/':
|
||||
b.append('/');
|
||||
break;
|
||||
case '"':
|
||||
b.append('"');
|
||||
break;
|
||||
case 'u':
|
||||
b.append((char)(
|
||||
(TypeUtil.convertHexDigit((byte)s.charAt(i++))<<24)+
|
||||
|
|
|
@ -157,7 +157,8 @@ public class QuotedStringTokenizerTest
|
|||
assertEquals("abc",QuotedStringTokenizer.quoteIfNeeded("abc", " ,"));
|
||||
assertEquals("\"a c\"",QuotedStringTokenizer.quoteIfNeeded("a c", " ,"));
|
||||
assertEquals("\"a'c\"",QuotedStringTokenizer.quoteIfNeeded("a'c", " ,"));
|
||||
assertEquals("\"a\\n\\r\\t\"",QuotedStringTokenizer.quote("a\n\r\t"));
|
||||
assertEquals("\"a\\n\\r\\t\"",QuotedStringTokenizer.quote("a\n\r\t"));
|
||||
assertEquals("\"\\u0000\\u001f\"",QuotedStringTokenizer.quote("\u0000\u001f"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -167,6 +168,7 @@ public class QuotedStringTokenizerTest
|
|||
assertEquals("a\"c",QuotedStringTokenizer.unquote("\"a\\\"c\""));
|
||||
assertEquals("a'c",QuotedStringTokenizer.unquote("\"a'c\""));
|
||||
assertEquals("a\n\r\t",QuotedStringTokenizer.unquote("\"a\\n\\r\\t\""));
|
||||
assertEquals("\u0000\u001f ",QuotedStringTokenizer.unquote("\"\u0000\u001f\u0020\""));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -199,6 +199,16 @@ public class JSONTest
|
|||
obj = Array.get(JSON.parse(string),0);
|
||||
assertTrue(obj instanceof Double);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Test
|
||||
public void testZeroByte()
|
||||
{
|
||||
String withzero="\u0000";
|
||||
String json = JSON.toString(withzero);
|
||||
System.err.println(json);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static class Gadget
|
||||
|
|
Loading…
Reference in New Issue