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' into develop

Close zendframework/zendframework#5771
Forward port zendframework/zendframework#5771
  • Loading branch information
Ocramius committed Mar 4, 2014
155 parents abb043f + fededdc + ecdf449 + 0ca1913 + 739bb00 + 1a55887 + 5d1699c + c3abd2b + 52a85cc + 09fac67 + fa67382 + e387fdb + 151cf71 + fa153f9 + e1db920 + 8f7f720 + 721f353 + 38e7a18 + 86ede54 + bb4f77a + 1ddebf3 + 0ffc57a + b946607 + 6f5587c + 315d8f1 + b6ad313 + f726ae3 + 7ad284f + 93b2293 + 6b9f3a9 + 8651985 + ed49c8f + 861b59b + ab368b3 + 42e779e + e446b23 + a77df97 + 83bebb3 + fac5fe1 + 0ecf55e + 6c9ab93 + d1576fd + 452dcfd + a5c8053 + 47591a8 + 4632b67 + 93389c9 + 59d4a69 + 6d7b139 + d060759 + a69361e + 65d2077 + ab34f04 + 16dc336 + 5ee0e7c + a3c5b47 + 0482e7d + 7349022 + 870fdc6 + 41980d5 + 8191f6d + 28e1f24 + c13913c + a787df2 + 700bec3 + 6279a0a + 59e1371 + 384145a + 2186cf3 + 266dd39 + 58cda5f + 6880bda + 9c58077 + f0a7ffa + af9ffb6 + 3a4f745 + f6ee3fa + ab1f64f + 37055aa + 785b6c6 + 965cde0 + b50b4db + cdc3a1d + d0638c2 + d2d69cb + f47f0b9 + c9b215a + 29a471c + 1914f43 + 0110db8 + 6cf95f3 + 3fe2af7 + fd2330d + d35c5af + 1360dd2 + 2d02d6c + f8c3676 + 478c122 + a64da1c + 56683e0 + f63f002 + b4c274d + 0183709 + 98549f4 + 9c7f3f3 + 94cf692 + 587a532 + a7779dc + e521397 + 018e2f8 + e7b79bc + d16a9d9 + b5fb5a8 + 32d1d88 + 87f6119 + 650b106 + 1911da8 + 7572e2b + 538d40c + dd11fea + db9d7ab + 30cabda + 5b6dcb4 + 0a224b1 + f2a96ec + e5b3b36 + 6ef088b + d28a29d + 6fd65f7 + f16fcce + 914239b + 7dfef7f + 21286c5 + e2cfbb1 + e17e6ff + 4a6cbed + 852ab61 + 54ababd + 963112c + 0bf4aec + f43e36c + 060bc4d + a0e4c2d + 3b96602 + 31c3210 + 7b56a57 + 2644a18 + 6fa1cc0 + d83698b + 8defff5 + b308684 + dac3848 + 5e24daa + 5d00816 + c3f70de commit fe42eb7
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 fe42eb7

Please sign in to comment.