Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/zendframework/zendframework#5771-escape-special-…
Browse files Browse the repository at this point in the history
…urlencoded-parameters-in-uri'

Close zendframework/zendframework#5771
  • Loading branch information
Ocramius committed Mar 4, 2014
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
23 changes: 17 additions & 6 deletions src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ class Uri implements UriInterface
/**
* Character classes defined in RFC-3986
*/
const CHAR_UNRESERVED = 'a-zA-Z0-9_\-\.~';
const CHAR_GEN_DELIMS = ':\/\?#\[\]@';
const CHAR_SUB_DELIMS = '!\$&\'\(\)\*\+,;=';
const CHAR_RESERVED = ':\/\?#\[\]@!\$&\'\(\)\*\+,;=';
const CHAR_UNRESERVED = 'a-zA-Z0-9_\-\.~';
const CHAR_GEN_DELIMS = ':\/\?#\[\]@';
const CHAR_SUB_DELIMS = '!\$&\'\(\)\*\+,;=';
const CHAR_RESERVED = ':\/\?#\[\]@!\$&\'\(\)\*\+,;=';
/**
* Not in the spec - those characters have special meaning in urlencoded query parameters
*/
const CHAR_QUERY_DELIMS = '!\$\'\(\)\*\,';

/**
* Host part types represented as binary masks
Expand Down Expand Up @@ -1304,7 +1308,7 @@ protected static function normalizeQuery($query)
$query = self::encodeQueryFragment(
self::decodeUrlEncodedChars(
$query,
'/[' . self::CHAR_UNRESERVED . self::CHAR_SUB_DELIMS . '%:@\/\?]/'
'/[' . self::CHAR_UNRESERVED . self::CHAR_QUERY_DELIMS . ':@\/\?]/'
)
);

Expand All @@ -1321,7 +1325,14 @@ protected static function normalizeQuery($query)
*/
protected static function normalizeFragment($fragment)
{
return static::normalizeQuery($fragment);
$fragment = self::encodeQueryFragment(
self::decodeUrlEncodedChars(
$fragment,
'/[' . self::CHAR_UNRESERVED . self::CHAR_SUB_DELIMS . '%:@\/\?]/'
)
);

return $fragment;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions test/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1246,9 +1246,9 @@ public function queryParamsArrayProvider()
'baz' => 'waka'
), 'foo=bar&baz=waka'),
array(array(
'some key' => 'some crazy value?!#[]',
'some key' => 'some crazy value?!#[]&=%+',
'1' => ''
), 'some%20key=some%20crazy%20value%3F%21%23%5B%5D&1='),
), 'some%20key=some%20crazy%20value%3F%21%23%5B%5D%26%3D%25%2B&1='),
array(array(
'array' => array('foo', 'bar', 'baz'),
'otherstuff[]' => 1234
Expand Down Expand Up @@ -1277,6 +1277,8 @@ public function normalizedUrlsProvider()
array('FOO:/bar/with space?que%3fry#frag%ment#', 'foo:/bar/with%20space?que?ry#frag%25ment%23'),
array('/path/%68%65%6c%6c%6f/world', '/path/hello/world'),
array('/foo/bar?url=http%3A%2F%2Fwww.example.com%2Fbaz', '/foo/bar?url=http://www.example.com/baz'),

array('/urlencoded/params?chars=' . urlencode('+&=;%20#'), '/urlencoded/params?chars=%2B%26%3D%3B%2520%23'),
array('File:///SitePages/fi%6ce%20has%20spaces', 'file:///SitePages/file%20has%20spaces'),
array('/foo/bar/../baz?do=action#showFragment', '/foo/baz?do=action#showFragment'),

Expand Down

0 comments on commit f58c365

Please sign in to comment.