@@ -22,35 +22,46 @@ public class CookieUtil {
22
22
23
23
private static final BitSet VALID_COOKIE_NAME_OCTETS = validCookieNameOctets (VALID_COOKIE_VALUE_OCTETS );
24
24
25
+ // cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
25
26
// US-ASCII characters excluding CTLs, whitespace, DQUOTE, comma, semicolon, and backslash
26
27
private static BitSet validCookieValueOctets () {
27
-
28
28
BitSet bits = new BitSet (8 );
29
- for (int i = 35 ; i < 127 ; i ++) {
30
- // US-ASCII characters excluding CTLs (%x00-1F / %x7F)
29
+ bits .set (0x21 );
30
+ for (int i = 0x23 ; i <= 0x2B ; i ++) {
31
+ bits .set (i );
32
+ }
33
+ for (int i = 0x2D ; i <= 0x3A ; i ++) {
34
+ bits .set (i );
35
+ }
36
+ for (int i = 0x3C ; i <= 0x5B ; i ++) {
37
+ bits .set (i );
38
+ }
39
+ for (int i = 0x5D ; i <= 0x7E ; i ++) {
31
40
bits .set (i );
32
41
}
33
- bits .set ('"' , false ); // exclude DQUOTE = %x22
34
- bits .set (',' , false ); // exclude comma = %x2C
35
- bits .set (';' , false ); // exclude semicolon = %x3B
36
- bits .set ('\\' , false ); // exclude backslash = %x5C
37
42
return bits ;
38
43
}
39
44
40
- // token = 1*<any CHAR except CTLs or separators>
41
- // separators = "(" | ")" | "<" | ">" | "@"
42
- // | "," | ";" | ":" | "\" | <">
43
- // | "/" | "[" | "]" | "?" | "="
44
- // | "{" | "}" | SP | HT
45
+ // token = 1*<any CHAR except CTLs or separators>
46
+ // separators = "(" | ")" | "<" | ">" | "@"
47
+ // | "," | ";" | ":" | "\" | <">
48
+ // | "/" | "[" | "]" | "?" | "="
49
+ // | "{" | "}" | SP | HT
45
50
private static BitSet validCookieNameOctets (BitSet validCookieValueOctets ) {
46
51
BitSet bits = new BitSet (8 );
47
- bits .or (validCookieValueOctets );
52
+ for (int i = 32 ; i < 127 ; i ++) {
53
+ bits .set (i );
54
+ }
48
55
bits .set ('(' , false );
49
56
bits .set (')' , false );
50
57
bits .set ('<' , false );
51
58
bits .set ('>' , false );
52
59
bits .set ('@' , false );
60
+ bits .set (',' , false );
61
+ bits .set (';' , false );
53
62
bits .set (':' , false );
63
+ bits .set ('\\' , false );
64
+ bits .set ('"' , false );
54
65
bits .set ('/' , false );
55
66
bits .set ('[' , false );
56
67
bits .set (']' , false );
@@ -62,7 +73,7 @@ private static BitSet validCookieNameOctets(BitSet validCookieValueOctets) {
62
73
bits .set ('\t' , false );
63
74
return bits ;
64
75
}
65
-
76
+
66
77
static int firstInvalidCookieNameOctet (CharSequence cs ) {
67
78
return firstInvalidOctet (cs , VALID_COOKIE_NAME_OCTETS );
68
79
}
@@ -103,10 +114,10 @@ static long computeExpiresAsMaxAge(String expires) {
103
114
return maxAgeMillis / 1000 + (maxAgeMillis % 1000 != 0 ? 1 : 0 );
104
115
}
105
116
}
106
-
117
+
107
118
return Long .MIN_VALUE ;
108
119
}
109
-
120
+
110
121
private CookieUtil () {
111
122
// Unused
112
123
}
0 commit comments