Index: java/org/apache/tomcat/util/http/CookieSupport.java =================================================================== --- java/org/apache/tomcat/util/http/CookieSupport.java (revision 1552781) +++ java/org/apache/tomcat/util/http/CookieSupport.java (working copy) @@ -147,15 +147,11 @@ * Returns true if the byte is a separator as defined by V0 of the cookie * spec. */ - public static final boolean isV0Separator(final char c) { - if (c < 0x20 || c >= 0x7f) { - if (c != 0x09) { - throw new IllegalArgumentException( - "Control character in cookie value or attribute."); - } + public static boolean isV0Separator(final char c) { + if (c < 0x20 && c != 0x09 || c >= 0x7f && c < 0xa0) { + throw new IllegalArgumentException("Control character in cookie value or attribute."); } - - return V0_SEPARATOR_FLAGS[c]; + return c < V0_SEPARATOR_FLAGS.length && V0_SEPARATOR_FLAGS[c]; } public static boolean isV0Token(String value) { @@ -187,15 +183,11 @@ * @throws IllegalArgumentException if a control character was supplied as * input */ - public static final boolean isHttpSeparator(final char c) { - if (c < 0x20 || c >= 0x7f) { - if (c != 0x09) { - throw new IllegalArgumentException( - "Control character in cookie value or attribute."); - } + public static boolean isHttpSeparator(final char c) { + if (c < 0x20 && c != 0x09 || c >= 0x7f && c < 0xa0) { + throw new IllegalArgumentException("Control character in cookie value or attribute."); } - - return HTTP_SEPARATOR_FLAGS[c]; + return c < HTTP_SEPARATOR_FLAGS.length && HTTP_SEPARATOR_FLAGS[c]; } public static boolean isHttpToken(String value) { Index: test/org/apache/tomcat/util/http/TestCookies.java =================================================================== --- test/org/apache/tomcat/util/http/TestCookies.java (revision 1552781) +++ test/org/apache/tomcat/util/http/TestCookies.java (working copy) @@ -17,9 +17,12 @@ package org.apache.tomcat.util.http; +import java.nio.charset.Charset; + import org.junit.Test; public class TestCookies { + private static final Charset ISO8859 = Charset.forName("ISO-8859-1"); @Test public void testCookies() throws Exception { @@ -30,6 +33,9 @@ test("foo=bar;a=b; ;", "foo", "bar", "a", "b"); test("foo=;a=b; ;", "a", "b"); test("foo;a=b; ;", "a", "b"); + // ISO-8859-1 value + test("foo=b\u00e1r; a=b", "foo", "b\u00e1r", "a", "b"); + // v1 test("$Version=1; foo=bar;a=b", "foo", "bar", "a", "b"); @@ -115,7 +121,7 @@ public static void test( String s, int val ) throws Exception { System.out.println("Processing [" + s + "]"); Cookies cs=new Cookies(null); - cs.processCookieHeader( s.getBytes(), 0, s.length()); + cs.processCookieHeader( s.getBytes(ISO8859), 0, s.length()); int num = cs.getCookieCount(); if (num != 1) throw new Exception("wrong number of cookies " + num); @@ -127,7 +133,7 @@ public static void test( String s ) throws Exception { System.out.println("Processing [" + s + "]"); Cookies cs=new Cookies(null); - cs.processCookieHeader( s.getBytes(), 0, s.length()); + cs.processCookieHeader( s.getBytes(ISO8859), 0, s.length()); int num = cs.getCookieCount(); for( int i=0; i< num ; i++ ) { @@ -139,7 +145,7 @@ public static void test( String s, String name, String val ) throws Exception { System.out.println("Processing [" + s + "]"); Cookies cs=new Cookies(null); - cs.processCookieHeader( s.getBytes(), 0, s.length()); + cs.processCookieHeader( s.getBytes(ISO8859), 0, s.length()); int num = cs.getCookieCount(); if (num != 1) @@ -156,7 +162,7 @@ public static void test( String s, String name, String val, String name2, String val2 ) throws Exception { System.out.println("Processing [" + s + "]"); Cookies cs=new Cookies(null); - cs.processCookieHeader( s.getBytes(), 0, s.length()); + cs.processCookieHeader( s.getBytes(ISO8859), 0, s.length()); int num = cs.getCookieCount(); if (num != 2) @@ -184,7 +190,7 @@ String val2, String name3, String val3 ) throws Exception { System.out.println("Processing [" + s + "]"); Cookies cs=new Cookies(null); - cs.processCookieHeader( s.getBytes(), 0, s.length()); + cs.processCookieHeader( s.getBytes(ISO8859), 0, s.length()); int num = cs.getCookieCount(); if (num != 3) @@ -222,7 +228,7 @@ String name4, String val4 ) throws Exception { System.out.println("Processing [" + s + "]"); Cookies cs=new Cookies(null); - cs.processCookieHeader( s.getBytes(), 0, s.length()); + cs.processCookieHeader( s.getBytes(ISO8859), 0, s.length()); int num = cs.getCookieCount(); if (num != 4)