fixing bug with arrays in querystring
This commit is contained in:
@@ -59,14 +59,15 @@ class HttpResponse {
|
|||||||
{
|
{
|
||||||
foreach (explode("\r\n", $headers) as $i => $line) {
|
foreach (explode("\r\n", $headers) as $i => $line) {
|
||||||
if ($i !== 0) {
|
if ($i !== 0) {
|
||||||
|
if (!empty($key) && substr($key, 0, 4) != "HTTP") {
|
||||||
|
$result[$key] = $value;
|
||||||
|
} else {
|
||||||
list ($key, $value) = explode(': ', $line);
|
list ($key, $value) = explode(': ', $line);
|
||||||
if (!empty($key) && substr($key, 0, 4) != "HTTP") $result[$key] = $value;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|||||||
@@ -113,17 +113,26 @@ class Unicorn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static function encodeUrl($url) {
|
private static function encodeUrl($url) {
|
||||||
$parsedUrl = parse_url($url);
|
// Parse URL into pieces
|
||||||
parse_str( $parsedUrl['query'], $query ); // generating an array by reference (yes, kinda weird)
|
$url_parsed = parse_url($url);
|
||||||
|
|
||||||
$result = $parsedUrl["scheme"] . "://" . $parsedUrl["host"] . (($parsedUrl["port"] != NULL ? ":" . $parsedUrl["port"] : "")) . $parsedUrl["path"] . "?";
|
// Build the basics bypassing notices
|
||||||
|
$scheme = $url_parsed['scheme'] . '://';
|
||||||
|
$host = $url_parsed['host'];
|
||||||
|
$port = ( isset($url_parsed['port']) ? $url_parsed['port'] : null );
|
||||||
|
$path = ( isset($url_parsed['path']) ? $url_parsed['path'] : null );
|
||||||
|
$query = ( isset($url_parsed['query']) ? $url_parsed['query'] : null );
|
||||||
|
|
||||||
|
// Do we need to encode anything?
|
||||||
if ($query != null) {
|
if ($query != null) {
|
||||||
foreach($query as $key => $val) {
|
// Break up the query into an array
|
||||||
$result .= $key . "=" . rawurlencode($val) . "&";
|
parse_str($url_parsed['query'], $query_parsed);
|
||||||
}
|
// Encode and build query based on RFC 1738
|
||||||
$result = substr($result, 0, strlen($result) - 1);
|
$query = '?'.http_build_query($query_parsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the completed URL
|
||||||
|
$result = $scheme . $host . $port . $path . $query;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user