diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 19f53a0..755322e 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -2,6 +2,48 @@ namespace Curl; +abstract class CurlCookieConst +{ + private static $RFC2616 = array(); + private static $RFC6265 = array(); + + public static function Init() { + self::$RFC2616 = array_fill_keys(array( + // RFC2616: "any CHAR except CTLs or separators". + '!', '#', '$', '%', '&', "'", '*', '+', '-', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', + 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', + 'W', 'X', 'Y', 'Z', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '|', '~', + ), true); + + self::$RFC6265 = array_fill_keys(array( + // RFC6265: "US-ASCII characters excluding CTLs, whitespace DQUOTE, comma, semicolon, and backslash". + // %x21 + '!', + // %x23-2B + '#', '$', '%', '&', "'", '(', ')', '*', '+', + // %x2D-3A + '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', + // %x3C-5B + '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', + // %x5D-7E + ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', + 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', + ), true); + } + + public static function RFC2616() { + return self::$RFC2616; + } + + public static function RFC6265() { + return self::$RFC6265; + } +} + +CurlCookieConst::Init(); + class Curl { const VERSION = '4.8.1'; @@ -543,12 +585,7 @@ class Curl { $name_chars = array(); foreach (str_split($key) as $name_char) { - if (!in_array($name_char, array( - // RFC2616: "any CHAR except CTLs or separators". - '!', '#', '$', '%', '&', "'", '*', '+', '-', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', - 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', - 'W', 'X', 'Y', 'Z', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', - 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '|', '~',), true)) { + if (!array_key_exists($name_char, CurlCookieConst::RFC2616)) { $name_chars[] = rawurlencode($name_char); } else { $name_chars[] = $name_char; @@ -557,20 +594,7 @@ class Curl $value_chars = array(); foreach (str_split($value) as $value_char) { - if (!in_array($value_char, array( - // RFC6265: "US-ASCII characters excluding CTLs, whitespace DQUOTE, comma, semicolon, and backslash". - // %x21 - '!', - // %x23-2B - '#', '$', '%', '&', "'", '(', ')', '*', '+', - // %x2D-3A - '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', - // %x3C-5B - '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', - 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', - // %x5D-7E - ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', - 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~',), true)) { + if (!array_key_exists($value_char, CurlCookieConst::RFC6265)) { $value_chars[] = rawurlencode($value_char); } else { $value_chars[] = $value_char;