Skip to content

Commit

Permalink
Merge pull request #23 from nextcloud/update-sabre-uri
Browse files Browse the repository at this point in the history
Update sabre/uri
  • Loading branch information
rullzer committed Dec 17, 2016
2 parents 7ddba87 + 251d47c commit 32f3284
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 63 deletions.
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
1 change: 1 addition & 0 deletions composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
106 changes: 53 additions & 53 deletions composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
]
}
]
11 changes: 11 additions & 0 deletions sabre/uri/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
------------------

Expand Down
17 changes: 17 additions & 0 deletions sabre/uri/lib/InvalidUriException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Sabre\Uri;

/**
* Invalid Uri
*
* This is thrown when an attempt was made to use Sabre\Uri parse a uri that
* it could not.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (https://evertpot.com/)
* @license http://sabre.io/license/
*/
class InvalidUriException extends \Exception {

}
2 changes: 1 addition & 1 deletion sabre/uri/lib/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class Version {
/**
* Full version number
*/
const VERSION = '1.1.1';
const VERSION = '1.2.0';

}
93 changes: 92 additions & 1 deletion sabre/uri/lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,13 @@ function($matches) {
$uri
);

$result = parse_url($uri);
if (!$result) {
$result = _parse_fallback($uri);
}

return
parse_url($uri) + [
$result + [
'scheme' => null,
'host' => null,
'path' => null,
Expand Down Expand Up @@ -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 = '
%^
//
(?: (?<user> [^:@]+) (: (?<pass> [^@]+)) @)?
(?<host> ( [^:/]* | \[ [^\]]+ \] ))
(?: : (?<port> [0-9]+))?
(?<path> / .*)?
$%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;
}

0 comments on commit 32f3284

Please sign in to comment.