Merge remote-tracking branch 'origin/jetty-7' into jetty-8
This commit is contained in:
commit
8241089364
|
@ -281,8 +281,8 @@ public class CookieCutter
|
|||
if (value!=null && name!=null)
|
||||
{
|
||||
// TODO handle unquoting during parsing! But quoting is uncommon
|
||||
name=QuotedStringTokenizer.unquote(name);
|
||||
value=QuotedStringTokenizer.unquote(value);
|
||||
name=QuotedStringTokenizer.unquoteOnly(name);
|
||||
value=QuotedStringTokenizer.unquoteOnly(value);
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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\""));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue