Skip to content

Commit

Permalink
Merge pull request #2497 from MashinaMashina/fix_URI_resolveRelativeURI
Browse files Browse the repository at this point in the history
Fix splitQueryPart()
  • Loading branch information
lonnieezell authored Jan 22, 2020
2 parents b51d8a5 + 9bd24a1 commit fedae3c
Showing 1 changed file with 1 addition and 68 deletions.
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

0 comments on commit fedae3c

Please sign in to comment.