Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix splitQueryPart() #2497

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 1 addition & 68 deletions system/HTTP/URI.php
Original file line number Diff line number Diff line change
Expand Up @@ -749,80 +749,13 @@ public function setQuery(string $query)
$query = substr($query, 1);
}

$temp = explode('&', $query);
$parts = [];

foreach ($temp as $index => $part)
{
list($key, $value) = $this->splitQueryPart($part);

// Only 1 part?
if (is_null($value))
{
$parts[$key] = null;
continue;
}

// URL Decode the value to protect
// from double-encoding a URL.
// Especially useful with the Pager.
$parts[$this->decode($key)] = $this->decode($value);
}

$this->query = $parts;
parse_str($query, $this->query);

return $this;
}

//--------------------------------------------------------------------

/**
* Checks the value to see if it has been urlencoded and decodes it if so.
* The urlencode check is not perfect but should catch most cases.
*
* @param string $value
*
* @return string
*/
protected function decode(string $value): string
{
if (empty($value))
{
return $value;
}

$decoded = urldecode($value);

// This won't catch all cases, specifically
// changing ' ' to '+' has the same length
// but doesn't really matter for our cases here.
return strlen($decoded) < strlen($value) ? $decoded : $value;
}

/**
* Split a query value into it's key/value elements, if both
* are present.
*
* @param $part
*
* @return array|null
*/
protected function splitQueryPart(string $part)
{
$parts = explode('=', $part, 2);

// If there's only a single element, no pair,
// then we return null
if (count($parts) === 1)
{
$parts = null;
}

return $parts;
}

//--------------------------------------------------------------------

/**
* A convenience method to pass an array of items in as the Query
* portion of the URI.
Expand Down