diff --git a/composer.lock b/composer.lock index 8af006ed9..20169e897 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "641586bfbbc76b68f47359d62e729d22", - "content-hash": "2408eab0e3c7aa1a1412f3dc86500329", + "hash": "f34b0dc10c6d9ddd6fd1296d2f4b5525", + "content-hash": "5da1e28d01bc81574941e20e05c6dcba", "packages": [ { "name": "bantu/ini-get-wrapper", @@ -2226,16 +2226,16 @@ }, { "name": "sabre/uri", - "version": "1.1.1", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/fruux/sabre-uri.git", - "reference": "258b72540fe3f2c0bb395cb40e56f9ae409f93b5" + "reference": "8545a3335f741d4b7700bb14efb41b4c03775dcd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fruux/sabre-uri/zipball/258b72540fe3f2c0bb395cb40e56f9ae409f93b5", - "reference": "258b72540fe3f2c0bb395cb40e56f9ae409f93b5", + "url": "https://api.github.com/repos/fruux/sabre-uri/zipball/8545a3335f741d4b7700bb14efb41b4c03775dcd", + "reference": "8545a3335f741d4b7700bb14efb41b4c03775dcd", "shasum": "" }, "require": { @@ -2273,7 +2273,7 @@ "uri", "url" ], - "time": "2016-10-27 04:56:33" + "time": "2016-12-07 01:17:59" }, { "name": "sabre/vobject", diff --git a/composer/autoload_classmap.php b/composer/autoload_classmap.php index 3d721f2d2..d6712299f 100644 --- a/composer/autoload_classmap.php +++ b/composer/autoload_classmap.php @@ -1237,6 +1237,7 @@ 'Sabre\\HTTP\\URLUtil' => $vendorDir . '/sabre/http/lib/URLUtil.php', 'Sabre\\HTTP\\Util' => $vendorDir . '/sabre/http/lib/Util.php', 'Sabre\\HTTP\\Version' => $vendorDir . '/sabre/http/lib/Version.php', + 'Sabre\\Uri\\InvalidUriException' => $vendorDir . '/sabre/uri/lib/InvalidUriException.php', 'Sabre\\Uri\\Version' => $vendorDir . '/sabre/uri/lib/Version.php', 'Sabre\\VObject\\BirthdayCalendarGenerator' => $vendorDir . '/sabre/vobject/lib/BirthdayCalendarGenerator.php', 'Sabre\\VObject\\Cli' => $vendorDir . '/sabre/vobject/lib/Cli.php', diff --git a/composer/autoload_real.php b/composer/autoload_real.php index 56d69c0f3..181330266 100644 --- a/composer/autoload_real.php +++ b/composer/autoload_real.php @@ -27,7 +27,7 @@ public static function getLoader() array_push($includePaths, get_include_path()); set_include_path(join(PATH_SEPARATOR, $includePaths)); - $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION'); + $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { require_once __DIR__ . '/autoload_static.php'; diff --git a/composer/autoload_static.php b/composer/autoload_static.php index f7fc9a8e8..c1a9939f0 100644 --- a/composer/autoload_static.php +++ b/composer/autoload_static.php @@ -1552,6 +1552,7 @@ class ComposerStaticInit2f23f73bc0cc116b4b1eee1521aa8652 'Sabre\\HTTP\\URLUtil' => __DIR__ . '/..' . '/sabre/http/lib/URLUtil.php', 'Sabre\\HTTP\\Util' => __DIR__ . '/..' . '/sabre/http/lib/Util.php', 'Sabre\\HTTP\\Version' => __DIR__ . '/..' . '/sabre/http/lib/Version.php', + 'Sabre\\Uri\\InvalidUriException' => __DIR__ . '/..' . '/sabre/uri/lib/InvalidUriException.php', 'Sabre\\Uri\\Version' => __DIR__ . '/..' . '/sabre/uri/lib/Version.php', 'Sabre\\VObject\\BirthdayCalendarGenerator' => __DIR__ . '/..' . '/sabre/vobject/lib/BirthdayCalendarGenerator.php', 'Sabre\\VObject\\Cli' => __DIR__ . '/..' . '/sabre/vobject/lib/Cli.php', diff --git a/composer/installed.json b/composer/installed.json index 68a3d56f3..1c6c57483 100644 --- a/composer/installed.json +++ b/composer/installed.json @@ -2578,59 +2578,6 @@ "description": "Symfony Process Component", "homepage": "https://symfony.com" }, - { - "name": "sabre/uri", - "version": "1.1.1", - "version_normalized": "1.1.1.0", - "source": { - "type": "git", - "url": "https://github.com/fruux/sabre-uri.git", - "reference": "258b72540fe3f2c0bb395cb40e56f9ae409f93b5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/fruux/sabre-uri/zipball/258b72540fe3f2c0bb395cb40e56f9ae409f93b5", - "reference": "258b72540fe3f2c0bb395cb40e56f9ae409f93b5", - "shasum": "" - }, - "require": { - "php": ">=5.4.7" - }, - "require-dev": { - "phpunit/phpunit": "*", - "sabre/cs": "~1.0.0" - }, - "time": "2016-10-27 04:56:33", - "type": "library", - "installation-source": "dist", - "autoload": { - "files": [ - "lib/functions.php" - ], - "psr-4": { - "Sabre\\Uri\\": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Evert Pot", - "email": "me@evertpot.com", - "homepage": "http://evertpot.com/", - "role": "Developer" - } - ], - "description": "Functions for making sense out of URIs.", - "homepage": "http://sabre.io/uri/", - "keywords": [ - "rfc3986", - "uri", - "url" - ] - }, { "name": "sabre/xml", "version": "1.5.0", @@ -2987,5 +2934,58 @@ "framework", "iCalendar" ] + }, + { + "name": "sabre/uri", + "version": "1.2.0", + "version_normalized": "1.2.0.0", + "source": { + "type": "git", + "url": "https://github.com/fruux/sabre-uri.git", + "reference": "8545a3335f741d4b7700bb14efb41b4c03775dcd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fruux/sabre-uri/zipball/8545a3335f741d4b7700bb14efb41b4c03775dcd", + "reference": "8545a3335f741d4b7700bb14efb41b4c03775dcd", + "shasum": "" + }, + "require": { + "php": ">=5.4.7" + }, + "require-dev": { + "phpunit/phpunit": "*", + "sabre/cs": "~1.0.0" + }, + "time": "2016-12-07 01:17:59", + "type": "library", + "installation-source": "dist", + "autoload": { + "files": [ + "lib/functions.php" + ], + "psr-4": { + "Sabre\\Uri\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Evert Pot", + "email": "me@evertpot.com", + "homepage": "http://evertpot.com/", + "role": "Developer" + } + ], + "description": "Functions for making sense out of URIs.", + "homepage": "http://sabre.io/uri/", + "keywords": [ + "rfc3986", + "uri", + "url" + ] } ] diff --git a/sabre/uri/CHANGELOG.md b/sabre/uri/CHANGELOG.md index 0c1f9d957..a30e45139 100644 --- a/sabre/uri/CHANGELOG.md +++ b/sabre/uri/CHANGELOG.md @@ -1,6 +1,17 @@ ChangeLog ========= +1.2.0 (2016-12-06) +------------------ + +* Now throwing `InvalidUriException` if a uri passed to the `parse` function + is invalid or could not be parsed. +* #11: Fix support for URIs that start with a triple slash. PHP's `parse_uri()` + doesn't support them, so we now have a pure-php fallback in case it fails. +* #9: Fix support for relative URI's that have a non-uri encoded colon `:` in + them. + + 1.1.1 (2016-10-27) ------------------ diff --git a/sabre/uri/lib/InvalidUriException.php b/sabre/uri/lib/InvalidUriException.php new file mode 100644 index 000000000..0385fd462 --- /dev/null +++ b/sabre/uri/lib/InvalidUriException.php @@ -0,0 +1,17 @@ + null, 'host' => null, 'path' => null, @@ -280,3 +285,89 @@ function split($path) { return [null,null]; } + +/** + * This function is another implementation of parse_url, except this one is + * fully written in PHP. + * + * The reason is that the PHP bug team is not willing to admit that there are + * bugs in the parse_url implementation. + * + * This function is only called if the main parse method fails. It's pretty + * crude and probably slow, so the original parse_url is usually preferred. + * + * @param string $uri + * @return array + */ +function _parse_fallback($uri) { + + // Normally a URI must be ASCII, however. However, often it's not and + // parse_url might corrupt these strings. + // + // For that reason we take any non-ascii characters from the uri and + // uriencode them first. + $uri = preg_replace_callback( + '/[^[:ascii:]]/u', + function($matches) { + return rawurlencode($matches[0]); + }, + $uri + ); + + $result = [ + 'scheme' => null, + 'host' => null, + 'port' => null, + 'user' => null, + 'path' => null, + 'fragment' => null, + 'query' => null, + ]; + + if (preg_match('% ^([A-Za-z][A-Za-z0-9+-\.]+): %x', $uri, $matches)) { + + $result['scheme'] = $matches[1]; + // Take what's left. + $uri = substr($uri, strlen($result['scheme']) + 1); + + } + + // Taking off a fragment part + if (strpos($uri, '#')) { + list($uri, $result['fragment']) = explode('#', $uri, 2); + } + // Taking off the query part + if (strpos($uri, '?')) { + list($uri, $result['query']) = explode('?', $uri, 2); + } + + if (substr($uri, 0, 3) === '///') { + // The triple slash uris are a bit unusual, but we have special handling + // for them. + $result['path'] = substr($uri, 2); + $result['host'] = ''; + } elseif (substr($uri, 0, 2) === '//') { + // Uris that have an authority part. + $regex = ' + %^ + // + (?: (? [^:@]+) (: (? [^@]+)) @)? + (? ( [^:/]* | \[ [^\]]+ \] )) + (?: : (? [0-9]+))? + (? / .*)? + $%x + '; + if (!preg_match($regex, $uri, $matches)) { + throw new InvalidUriException('Invalid, or could not parse URI'); + } + if ($matches['host']) $result['host'] = $matches['host']; + if ($matches['port']) $result['port'] = (int)$matches['port']; + if (isset($matches['path'])) $result['path'] = $matches['path']; + if ($matches['user']) $result['user'] = $matches['user']; + if ($matches['pass']) $result['pass'] = $matches['pass']; + } else { + $result['path'] = $uri; + } + + return $result; +}