2
2
3
3
namespace Curl ;
4
4
5
+ abstract class CurlCookieConst
6
+ {
7
+ private static $ RFC2616 = array ();
8
+ private static $ RFC6265 = array ();
9
+
10
+ public static function Init () {
11
+ self ::$ RFC2616 = array_fill_keys (array (
12
+ // RFC2616: "any CHAR except CTLs or separators".
13
+ '! ' , '# ' , '$ ' , '% ' , '& ' , "' " , '* ' , '+ ' , '- ' , '. ' , '0 ' , '1 ' , '2 ' , '3 ' , '4 ' , '5 ' , '6 ' , '7 ' , '8 ' , '9 ' , 'A ' ,
14
+ 'B ' , 'C ' , 'D ' , 'E ' , 'F ' , 'G ' , 'H ' , 'I ' , 'J ' , 'K ' , 'L ' , 'M ' , 'N ' , 'O ' , 'P ' , 'Q ' , 'R ' , 'S ' , 'T ' , 'U ' , 'V ' ,
15
+ 'W ' , 'X ' , 'Y ' , 'Z ' , '^ ' , '_ ' , '` ' , 'a ' , 'b ' , 'c ' , 'd ' , 'e ' , 'f ' , 'g ' , 'h ' , 'i ' , 'j ' , 'k ' , 'l ' , 'm ' , 'n ' ,
16
+ 'o ' , 'p ' , 'q ' , 'r ' , 's ' , 't ' , 'u ' , 'v ' , 'w ' , 'x ' , 'y ' , 'z ' , '| ' , '~ ' ,
17
+ ), true );
18
+
19
+ self ::$ RFC6265 = array_fill_keys (array (
20
+ // RFC6265: "US-ASCII characters excluding CTLs, whitespace DQUOTE, comma, semicolon, and backslash".
21
+ // %x21
22
+ '! ' ,
23
+ // %x23-2B
24
+ '# ' , '$ ' , '% ' , '& ' , "' " , '( ' , ') ' , '* ' , '+ ' ,
25
+ // %x2D-3A
26
+ '- ' , '. ' , '/ ' , '0 ' , '1 ' , '2 ' , '3 ' , '4 ' , '5 ' , '6 ' , '7 ' , '8 ' , '9 ' , ': ' ,
27
+ // %x3C-5B
28
+ '< ' , '= ' , '> ' , '? ' , '@ ' , 'A ' , 'B ' , 'C ' , 'D ' , 'E ' , 'F ' , 'G ' , 'H ' , 'I ' , 'J ' , 'K ' , 'L ' , 'M ' , 'N ' , 'O ' , 'P ' ,
29
+ 'Q ' , 'R ' , 'S ' , 'T ' , 'U ' , 'V ' , 'W ' , 'X ' , 'Y ' , 'Z ' , '[ ' ,
30
+ // %x5D-7E
31
+ '] ' , '^ ' , '_ ' , '` ' , 'a ' , 'b ' , 'c ' , 'd ' , 'e ' , 'f ' , 'g ' , 'h ' , 'i ' , 'j ' , 'k ' , 'l ' , 'm ' , 'n ' , 'o ' , 'p ' , 'q ' ,
32
+ 'r ' , 's ' , 't ' , 'u ' , 'v ' , 'w ' , 'x ' , 'y ' , 'z ' , '{ ' , '| ' , '} ' , '~ ' ,
33
+ ), true );
34
+ }
35
+
36
+ public static function RFC2616 () {
37
+ return self ::$ RFC2616 ;
38
+ }
39
+
40
+ public static function RFC6265 () {
41
+ return self ::$ RFC6265 ;
42
+ }
43
+ }
44
+
45
+ CurlCookieConst::Init ();
46
+
5
47
class Curl
6
48
{
7
49
const VERSION = '4.8.1 ' ;
@@ -543,12 +585,7 @@ public function setCookie($key, $value)
543
585
{
544
586
$ name_chars = array ();
545
587
foreach (str_split ($ key ) as $ name_char ) {
546
- if (!in_array ($ name_char , array (
547
- // RFC2616: "any CHAR except CTLs or separators".
548
- '! ' , '# ' , '$ ' , '% ' , '& ' , "' " , '* ' , '+ ' , '- ' , '. ' , '0 ' , '1 ' , '2 ' , '3 ' , '4 ' , '5 ' , '6 ' , '7 ' , '8 ' , '9 ' , 'A ' ,
549
- 'B ' , 'C ' , 'D ' , 'E ' , 'F ' , 'G ' , 'H ' , 'I ' , 'J ' , 'K ' , 'L ' , 'M ' , 'N ' , 'O ' , 'P ' , 'Q ' , 'R ' , 'S ' , 'T ' , 'U ' , 'V ' ,
550
- 'W ' , 'X ' , 'Y ' , 'Z ' , '^ ' , '_ ' , '` ' , 'a ' , 'b ' , 'c ' , 'd ' , 'e ' , 'f ' , 'g ' , 'h ' , 'i ' , 'j ' , 'k ' , 'l ' , 'm ' , 'n ' ,
551
- 'o ' , 'p ' , 'q ' , 'r ' , 's ' , 't ' , 'u ' , 'v ' , 'w ' , 'x ' , 'y ' , 'z ' , '| ' , '~ ' ,), true )) {
588
+ if (!array_key_exists ($ name_char , CurlCookieConst::RFC2616 )) {
552
589
$ name_chars [] = rawurlencode ($ name_char );
553
590
} else {
554
591
$ name_chars [] = $ name_char ;
@@ -557,20 +594,7 @@ public function setCookie($key, $value)
557
594
558
595
$ value_chars = array ();
559
596
foreach (str_split ($ value ) as $ value_char ) {
560
- if (!in_array ($ value_char , array (
561
- // RFC6265: "US-ASCII characters excluding CTLs, whitespace DQUOTE, comma, semicolon, and backslash".
562
- // %x21
563
- '! ' ,
564
- // %x23-2B
565
- '# ' , '$ ' , '% ' , '& ' , "' " , '( ' , ') ' , '* ' , '+ ' ,
566
- // %x2D-3A
567
- '- ' , '. ' , '/ ' , '0 ' , '1 ' , '2 ' , '3 ' , '4 ' , '5 ' , '6 ' , '7 ' , '8 ' , '9 ' , ': ' ,
568
- // %x3C-5B
569
- '< ' , '= ' , '> ' , '? ' , '@ ' , 'A ' , 'B ' , 'C ' , 'D ' , 'E ' , 'F ' , 'G ' , 'H ' , 'I ' , 'J ' , 'K ' , 'L ' , 'M ' , 'N ' , 'O ' , 'P ' ,
570
- 'Q ' , 'R ' , 'S ' , 'T ' , 'U ' , 'V ' , 'W ' , 'X ' , 'Y ' , 'Z ' , '[ ' ,
571
- // %x5D-7E
572
- '] ' , '^ ' , '_ ' , '` ' , 'a ' , 'b ' , 'c ' , 'd ' , 'e ' , 'f ' , 'g ' , 'h ' , 'i ' , 'j ' , 'k ' , 'l ' , 'm ' , 'n ' , 'o ' , 'p ' , 'q ' ,
573
- 'r ' , 's ' , 't ' , 'u ' , 'v ' , 'w ' , 'x ' , 'y ' , 'z ' , '{ ' , '| ' , '} ' , '~ ' ,), true )) {
597
+ if (!array_key_exists ($ value_char , CurlCookieConst::RFC6265 )) {
574
598
$ value_chars [] = rawurlencode ($ value_char );
575
599
} else {
576
600
$ value_chars [] = $ value_char ;
0 commit comments