Merge remote-tracking branch 'origin/jetty-8'
This commit is contained in:
commit
ba8057867e
|
@ -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
|
||||
{
|
||||
|
|
|
@ -409,6 +409,47 @@ public class QuotedStringTokenizer
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** 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.
|
||||
* @param s The string to unquote.
|
||||
|
|
|
@ -179,4 +179,15 @@ public class QuotedStringTokenizerTest
|
|||
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\""));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue