View | Details | Raw Unified | Return to bug 55917
Collapse All | Expand All

(-)java/org/apache/tomcat/util/http/CookieSupport.java (-16 / +8 lines)
Lines 147-161 Link Here
147
     * Returns true if the byte is a separator as defined by V0 of the cookie
147
     * Returns true if the byte is a separator as defined by V0 of the cookie
148
     * spec.
148
     * spec.
149
     */
149
     */
150
    public static final boolean isV0Separator(final char c) {
150
    public static boolean isV0Separator(final char c) {
151
        if (c < 0x20 || c >= 0x7f) {
151
        if (c < 0x20 && c != 0x09 || c >= 0x7f && c < 0xa0) {
152
            if (c != 0x09) {
152
            throw new IllegalArgumentException("Control character in cookie value or attribute.");
153
                throw new IllegalArgumentException(
154
                        "Control character in cookie value or attribute.");
155
            }
156
        }
153
        }
157
154
        return c < V0_SEPARATOR_FLAGS.length && V0_SEPARATOR_FLAGS[c];
158
        return V0_SEPARATOR_FLAGS[c];
159
    }
155
    }
160
156
161
    public static boolean isV0Token(String value) {
157
    public static boolean isV0Token(String value) {
Lines 187-201 Link Here
187
     * @throws IllegalArgumentException if a control character was supplied as
183
     * @throws IllegalArgumentException if a control character was supplied as
188
     *         input
184
     *         input
189
     */
185
     */
190
    public static final boolean isHttpSeparator(final char c) {
186
    public static boolean isHttpSeparator(final char c) {
191
        if (c < 0x20 || c >= 0x7f) {
187
        if (c < 0x20 && c != 0x09 || c >= 0x7f && c < 0xa0) {
192
            if (c != 0x09) {
188
            throw new IllegalArgumentException("Control character in cookie value or attribute.");
193
                throw new IllegalArgumentException(
194
                        "Control character in cookie value or attribute.");
195
            }
196
        }
189
        }
197
190
        return c < HTTP_SEPARATOR_FLAGS.length && HTTP_SEPARATOR_FLAGS[c];
198
        return HTTP_SEPARATOR_FLAGS[c];
199
    }
191
    }
200
192
201
    public static boolean isHttpToken(String value) {
193
    public static boolean isHttpToken(String value) {
(-)test/org/apache/tomcat/util/http/TestCookies.java (-6 / +12 lines)
Lines 17-25 Link Here
17
17
18
package org.apache.tomcat.util.http;
18
package org.apache.tomcat.util.http;
19
19
20
import java.nio.charset.Charset;
21
20
import org.junit.Test;
22
import org.junit.Test;
21
23
22
public class TestCookies {
24
public class TestCookies {
25
    private static final Charset ISO8859 = Charset.forName("ISO-8859-1");
23
26
24
    @Test
27
    @Test
25
    public void testCookies() throws Exception {
28
    public void testCookies() throws Exception {
Lines 30-35 Link Here
30
        test("foo=bar;a=b; ;", "foo", "bar", "a", "b");
33
        test("foo=bar;a=b; ;", "foo", "bar", "a", "b");
31
        test("foo=;a=b; ;",  "a", "b");
34
        test("foo=;a=b; ;",  "a", "b");
32
        test("foo;a=b; ;", "a", "b");
35
        test("foo;a=b; ;", "a", "b");
36
        // ISO-8859-1 value
37
        test("foo=b\u00e1r; a=b", "foo", "b\u00e1r", "a", "b");
38
33
        // v1
39
        // v1
34
        test("$Version=1; foo=bar;a=b", "foo", "bar", "a", "b");
40
        test("$Version=1; foo=bar;a=b", "foo", "bar", "a", "b");
35
41
Lines 115-121 Link Here
115
    public static void test( String s, int val ) throws Exception {
121
    public static void test( String s, int val ) throws Exception {
116
        System.out.println("Processing [" + s + "]");
122
        System.out.println("Processing [" + s + "]");
117
        Cookies cs=new Cookies(null);
123
        Cookies cs=new Cookies(null);
118
        cs.processCookieHeader( s.getBytes(), 0, s.length());
124
        cs.processCookieHeader( s.getBytes(ISO8859), 0, s.length());
119
        int num = cs.getCookieCount();
125
        int num = cs.getCookieCount();
120
        if (num != 1)
126
        if (num != 1)
121
          throw new Exception("wrong number of cookies " + num);
127
          throw new Exception("wrong number of cookies " + num);
Lines 127-133 Link Here
127
    public static void test( String s ) throws Exception {
133
    public static void test( String s ) throws Exception {
128
        System.out.println("Processing [" + s + "]");
134
        System.out.println("Processing [" + s + "]");
129
        Cookies cs=new Cookies(null);
135
        Cookies cs=new Cookies(null);
130
        cs.processCookieHeader( s.getBytes(), 0, s.length());
136
        cs.processCookieHeader( s.getBytes(ISO8859), 0, s.length());
131
137
132
        int num = cs.getCookieCount();
138
        int num = cs.getCookieCount();
133
        for( int i=0; i< num ; i++ ) {
139
        for( int i=0; i< num ; i++ ) {
Lines 139-145 Link Here
139
    public static void test( String s, String name, String val ) throws Exception {
145
    public static void test( String s, String name, String val ) throws Exception {
140
        System.out.println("Processing [" + s + "]");
146
        System.out.println("Processing [" + s + "]");
141
        Cookies cs=new Cookies(null);
147
        Cookies cs=new Cookies(null);
142
        cs.processCookieHeader( s.getBytes(), 0, s.length());
148
        cs.processCookieHeader( s.getBytes(ISO8859), 0, s.length());
143
149
144
        int num = cs.getCookieCount();
150
        int num = cs.getCookieCount();
145
        if (num != 1)
151
        if (num != 1)
Lines 156-162 Link Here
156
    public static void test( String s, String name, String val, String name2, String val2 ) throws Exception {
162
    public static void test( String s, String name, String val, String name2, String val2 ) throws Exception {
157
        System.out.println("Processing [" + s + "]");
163
        System.out.println("Processing [" + s + "]");
158
        Cookies cs=new Cookies(null);
164
        Cookies cs=new Cookies(null);
159
        cs.processCookieHeader( s.getBytes(), 0, s.length());
165
        cs.processCookieHeader( s.getBytes(ISO8859), 0, s.length());
160
166
161
        int num = cs.getCookieCount();
167
        int num = cs.getCookieCount();
162
        if (num != 2)
168
        if (num != 2)
Lines 184-190 Link Here
184
                             String val2, String name3, String val3 ) throws Exception {
190
                             String val2, String name3, String val3 ) throws Exception {
185
        System.out.println("Processing [" + s + "]");
191
        System.out.println("Processing [" + s + "]");
186
        Cookies cs=new Cookies(null);
192
        Cookies cs=new Cookies(null);
187
        cs.processCookieHeader( s.getBytes(), 0, s.length());
193
        cs.processCookieHeader( s.getBytes(ISO8859), 0, s.length());
188
194
189
        int num = cs.getCookieCount();
195
        int num = cs.getCookieCount();
190
        if (num != 3)
196
        if (num != 3)
Lines 222-228 Link Here
222
                             String name4, String val4 ) throws Exception {
228
                             String name4, String val4 ) throws Exception {
223
        System.out.println("Processing [" + s + "]");
229
        System.out.println("Processing [" + s + "]");
224
        Cookies cs=new Cookies(null);
230
        Cookies cs=new Cookies(null);
225
        cs.processCookieHeader( s.getBytes(), 0, s.length());
231
        cs.processCookieHeader( s.getBytes(ISO8859), 0, s.length());
226
232
227
        int num = cs.getCookieCount();
233
        int num = cs.getCookieCount();
228
        if (num != 4)
234
        if (num != 4)

Return to bug 55917