Why do we not encode = and & in query strings? I am referencing RFC 3986 but cannot find where it says that we should not encode these characters. Using Guzzle, it doesn't seem they encode anything really.
Take for example the query string: key1='1'&key2='2'
, shouldn't this be encoded as key1%3D%271%27%26key2%3D%272%27
? If I plug key1='1'&key2='2'
into chrome as a query string (e.g. www.google.com?key1='1'&key2='2'
), it appears as key1=%271%27&key2=%272%27
, which does not match guzzle. Guzzle outputs key1='1'&key2='2'
. Guzzle's encoding algorithm is below:
private static $charUnreserved = 'a-zA-Z0-9_\-\.~';
private static $charSubDelims = '!\$&\'\(\)\*\+,;=';
public function encode()
{
return preg_replace_callback(
'/(?:[^' . self::$charUnreserved . self::$charSubDelims . '%:@\/\?]++|%(?![A-Fa-f0-9]{2}))/',
function ($match) {
return urlencode($match[0]);
},
$str
);
}