Mercurial > hg > isophonics-drupal-site
diff vendor/zendframework/zend-diactoros/src/Uri.php @ 12:7a779792577d
Update Drupal core to v8.4.5 (via Composer)
author | Chris Cannam |
---|---|
date | Fri, 23 Feb 2018 15:52:07 +0000 |
parents | 4c8ae668cc8c |
children | 5fb285c0d0e3 |
line wrap: on
line diff
--- a/vendor/zendframework/zend-diactoros/src/Uri.php Fri Feb 23 15:51:18 2018 +0000 +++ b/vendor/zendframework/zend-diactoros/src/Uri.php Fri Feb 23 15:52:07 2018 +0000 @@ -1,9 +1,7 @@ <?php /** - * Zend Framework (http://framework.zend.com/) - * - * @see http://github.com/zendframework/zend-diactoros for the canonical source repository - * @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com) + * @see https://github.com/zendframework/zend-diactoros for the canonical source repository + * @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com) * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License */ @@ -25,14 +23,14 @@ class Uri implements UriInterface { /** - * Sub-delimiters used in query strings and fragments. + * Sub-delimiters used in user info, query strings and fragments. * * @const string */ const CHAR_SUB_DELIMS = '!\$&\'\(\)\*\+,;='; /** - * Unreserved characters used in paths, query strings, and fragments. + * Unreserved characters used in user info, paths, query strings, and fragments. * * @const string */ @@ -166,6 +164,10 @@ } /** + * Retrieve the user-info part of the URI. + * + * This value is percent-encoded, per RFC 3986 Section 3.2.1. + * * {@inheritdoc} */ public function getUserInfo() @@ -232,7 +234,7 @@ if ($scheme === $this->scheme) { // Do nothing if no change was made. - return clone $this; + return $this; } $new = clone $this; @@ -242,6 +244,11 @@ } /** + * Create and return a new instance containing the provided user credentials. + * + * The value will be percent-encoded in the new instance, but with measures + * taken to prevent double-encoding. + * * {@inheritdoc} */ public function withUserInfo($user, $password = null) @@ -261,14 +268,14 @@ )); } - $info = $user; + $info = $this->filterUserInfoPart($user); if ($password) { - $info .= ':' . $password; + $info .= ':' . $this->filterUserInfoPart($password); } if ($info === $this->userInfo) { // Do nothing if no change was made. - return clone $this; + return $this; } $new = clone $this; @@ -292,7 +299,7 @@ if ($host === $this->host) { // Do nothing if no change was made. - return clone $this; + return $this; } $new = clone $this; @@ -319,10 +326,10 @@ if ($port === $this->port) { // Do nothing if no change was made. - return clone $this; + return $this; } - if ($port !== null && $port < 1 || $port > 65535) { + if ($port !== null && ($port < 1 || $port > 65535)) { throw new InvalidArgumentException(sprintf( 'Invalid port "%d" specified; must be a valid TCP/UDP port', $port @@ -362,7 +369,7 @@ if ($path === $this->path) { // Do nothing if no change was made. - return clone $this; + return $this; } $new = clone $this; @@ -392,7 +399,7 @@ if ($query === $this->query) { // Do nothing if no change was made. - return clone $this; + return $this; } $new = clone $this; @@ -418,7 +425,7 @@ if ($fragment === $this->fragment) { // Do nothing if no change was made. - return clone $this; + return $this; } $new = clone $this; @@ -443,7 +450,7 @@ } $this->scheme = isset($parts['scheme']) ? $this->filterScheme($parts['scheme']) : ''; - $this->userInfo = isset($parts['user']) ? $parts['user'] : ''; + $this->userInfo = isset($parts['user']) ? $this->filterUserInfoPart($parts['user']) : ''; $this->host = isset($parts['host']) ? $parts['host'] : ''; $this->port = isset($parts['port']) ? $parts['port'] : null; $this->path = isset($parts['path']) ? $this->filterPath($parts['path']) : ''; @@ -548,6 +555,23 @@ } /** + * Filters a part of user info in a URI to ensure it is properly encoded. + * + * @param string $part + * @return string + */ + private function filterUserInfoPart($part) + { + // Note the addition of `%` to initial charset; this allows `|` portion + // to match and thus prevent double-encoding. + return preg_replace_callback( + '/(?:[^%' . self::CHAR_UNRESERVED . self::CHAR_SUB_DELIMS . ']+|%(?![A-Fa-f0-9]{2}))/u', + [$this, 'urlEncodeChar'], + $part + ); + } + + /** * Filters the path of a URI to ensure it is properly encoded. * * @param string $path @@ -624,7 +648,7 @@ /** * Filter a fragment value to ensure it is properly encoded. * - * @param null|string $fragment + * @param string $fragment * @return string */ private function filterFragment($fragment)