diff options
author | zotlabs <root@sillystring.adeis.uow.edu.au> | 2017-03-16 11:42:06 +1100 |
---|---|---|
committer | zotlabs <root@sillystring.adeis.uow.edu.au> | 2017-03-16 11:42:06 +1100 |
commit | 8d4744d115036dd7ec4169f8b1fdebebac6fb602 (patch) | |
tree | aa8c18d6c51256fb94048dccf0c822b0281ad894 /vendor/sabre/uri/lib/functions.php | |
parent | df6c07aaadda2e89d2843bae136f813c909637ba (diff) | |
download | volse-hubzilla-8d4744d115036dd7ec4169f8b1fdebebac6fb602.tar.gz volse-hubzilla-8d4744d115036dd7ec4169f8b1fdebebac6fb602.tar.bz2 volse-hubzilla-8d4744d115036dd7ec4169f8b1fdebebac6fb602.zip |
new composer.lock for red
Diffstat (limited to 'vendor/sabre/uri/lib/functions.php')
-rw-r--r-- | vendor/sabre/uri/lib/functions.php | 99 |
1 files changed, 95 insertions, 4 deletions
diff --git a/vendor/sabre/uri/lib/functions.php b/vendor/sabre/uri/lib/functions.php index 06181aef0..39b4a6f08 100644 --- a/vendor/sabre/uri/lib/functions.php +++ b/vendor/sabre/uri/lib/functions.php @@ -45,8 +45,8 @@ function resolve($basePath, $newPath) { $newParts = []; $newParts['scheme'] = $pick('scheme'); - $newParts['host'] = $pick('host'); - $newParts['port'] = $pick('port'); + $newParts['host'] = $pick('host'); + $newParts['port'] = $pick('port'); $path = ''; if ($delta['path']) { @@ -193,8 +193,13 @@ function parse($uri) { $uri ); + $result = parse_url($uri); + if (!$result) { + $result = _parse_fallback($uri); + } + return - parse_url($uri) + [ + $result + [ 'scheme' => null, 'host' => null, 'path' => null, @@ -233,7 +238,7 @@ function build(array $parts) { $uri = $parts['scheme'] . ':'; } - if ($authority) { + if ($authority || (!empty($parts['scheme']) && $parts['scheme'] === 'file')) { // No scheme, but there is a host. $uri .= '//' . $authority; @@ -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, '#') !== false) { + list($uri, $result['fragment']) = explode('#', $uri, 2); + } + // Taking off the query part + if (strpos($uri, '?') !== false) { + 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; +} |