Merge remote-tracking branch 'origin/jetty-8'

This commit is contained in:
Jan Bartel 2012-11-23 15:04:20 +11:00
commit ba8057867e
3 changed files with 54 additions and 2 deletions

View File

@ -278,8 +278,8 @@ public class CookieCutter
// If after processing the current character we have a value and a name, then it is a cookie
if (value!=null && name!=null)
{
name=QuotedStringTokenizer.unquote(name);
value=QuotedStringTokenizer.unquote(value);
name=QuotedStringTokenizer.unquoteOnly(name);
value=QuotedStringTokenizer.unquoteOnly(value);
try
{

View File

@ -408,6 +408,47 @@ public class QuotedStringTokenizer
throw new RuntimeException(e);
}
}
/* ------------------------------------------------------------ */
/** Unquote a string, NOT converting unicode sequences
* @param s The string to unquote.
* @return quoted string
*/
public static String unquoteOnly(String s)
{
if (s==null)
return null;
if (s.length()<2)
return s;
char first=s.charAt(0);
char last=s.charAt(s.length()-1);
if (first!=last || (first!='"' && first!='\''))
return s;
StringBuilder b = new StringBuilder(s.length() - 2);
boolean escape=false;
for (int i=1;i<s.length()-1;i++)
{
char c = s.charAt(i);
if (escape)
{
escape=false;
b.append(c);
}
else if (c=='\\')
{
escape=true;
}
else
{
b.append(c);
}
}
return b.toString();
}
/* ------------------------------------------------------------ */
/** Unquote a string.

View File

@ -178,5 +178,16 @@ public class QuotedStringTokenizerTest
assertEquals("ab\u001ec",QuotedStringTokenizer.unquote("ab\u001ec"));
assertEquals("ab\u001ec",QuotedStringTokenizer.unquote("\"ab\u001ec\""));
}
@Test
public void testUnquoteOnly()
{
assertEquals("abc",QuotedStringTokenizer.unquoteOnly("abc"));
assertEquals("a\"c",QuotedStringTokenizer.unquoteOnly("\"a\\\"c\""));
assertEquals("a'c",QuotedStringTokenizer.unquoteOnly("\"a'c\""));
assertEquals("a\\n\\r\\t",QuotedStringTokenizer.unquoteOnly("\"a\\\\n\\\\r\\\\t\""));
assertEquals("ba\\uXXXXaaa", QuotedStringTokenizer.unquoteOnly("\"ba\\\\uXXXXaaa\""));
}
}