pax_global_header00006660000000000000000000000064125200521160014504gustar00rootroot0000000000000052 comment=6bae7efdd9dfcfdb3edfc4362741e59ce4b64f42 sabre-uri-1.0.1/000077500000000000000000000000001252005211600133745ustar00rootroot00000000000000sabre-uri-1.0.1/.gitignore000066400000000000000000000001561252005211600153660ustar00rootroot00000000000000# Composer vendor/ composer.lock # Tests tests/cov/ # Composer binaries bin/phpunit bin/phpcs # Vim .*.swp sabre-uri-1.0.1/.travis.yml000066400000000000000000000010371252005211600155060ustar00rootroot00000000000000language: php php: - 5.4 - 5.5 - 5.6 - hhvm - 7 matrix: fast_finish: true allow_failures: - php: 7 script: - ./bin/phpunit --configuration tests/phpunit.xml.dist - ./bin/sabre-cs-fixer fix lib/ --dry-run --diff before_script: composer install --dev notifications: slack: rooms: secure: LVmBXAz0TKdB8dsB9Rt+M5+KnpStxEbOKuNVHN/lYOYmnB5CNogc/TDUKIFe5OUHAjGbn3xUy+tgBIME/RZLPAC6aAKpw0BPbGXYeagYlDBj9HUR9sUDrwV+l/75e4QWZPrUwS1dIa4ePirosIlYZwlwfGzEz8SgVY2x7BZFBEs= on_success: change on_failure: change sabre-uri-1.0.1/CHANGELOG.md000066400000000000000000000011221252005211600152010ustar00rootroot00000000000000ChangeLog ========= 1.0.1 (2015-04-28) ------------------ * #4: Using php-cs-fixer to automatically enforce conding standards. * #5: Resolving to and building `mailto:` urls were not correctly handled. 1.0.0 (2015-01-27) ------------------ * Added a `normalize` function. * Added a `buildUri` function. * Fixed a bug in the `resolve` when only a new fragment is specified. San José, CalConnect XXXII release! 0.0.1 (2014-11-17) ------------------ * First version! * Source was lifted from sabre/http package. * Provides a `resolve` and a `split` function. * Requires PHP 5.4.8 and up. sabre-uri-1.0.1/LICENSE000066400000000000000000000030411252005211600143770ustar00rootroot00000000000000Copyright (C) 2014-2015 fruux GmbH (https://fruux.com/) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name Sabre nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. sabre-uri-1.0.1/README.md000066400000000000000000000030001252005211600146440ustar00rootroot00000000000000sabre/uri ========= sabre/uri is a lightweight library that provides several functions for working with URIs, staying true to the rules of [RFC3986][2]. Partially inspired by [Node.js URL library][3], and created to solve real problems in PHP applications. 100% unitested and many tests are based on examples from RFC3986. The library provides the following functions: 1. `resolve` to resolve relative urls. 2. `normalize` to aid in comparing urls. 3. `parse`, which works like PHP's [parse_url][6]. 4. `build` to do the exact opposite of `parse`. 5. `split` to easily get the 'dirname' and 'basename' of a URL without all the problems those two functions have. Further reading --------------- * [Installation][7] * [Usage][8] Build status ------------ | branch | status | | ------ | ------ | | master | [![Build Status](https://travis-ci.org/fruux/sabre-uri.svg?branch=master)](https://travis-ci.org/fruux/sabre-uri) | Questions? ---------- Head over to the [sabre/dav mailinglist][4], or you can also just open a ticket on [GitHub][5]. Made at fruux ------------- This library is being developed by [fruux](https://fruux.com/). Drop us a line for commercial services or enterprise support. [1]: http://sabre.io/uri/ [2]: https://tools.ietf.org/html/rfc3986/ [3]: http://nodejs.org/api/url.html [4]: http://groups.google.com/group/sabredav-discuss [5]: https://github.com/fruux/sabre-uri/issues/ [6]: http://php.net/manual/en/function.parse-url.php [7]: http://sabre.io/uri/install/ [8]: http://sabre.io/uri/usage/ sabre-uri-1.0.1/composer.json000066400000000000000000000016331252005211600161210ustar00rootroot00000000000000{ "name": "sabre/uri", "description": "Functions for making sense out of URIs.", "keywords": [ "URI", "URL", "rfc3986" ], "homepage": "http://sabre.io/uri/", "license": "BSD-3-Clause", "require": { "php": ">=5.4.7" }, "authors": [ { "name": "Evert Pot", "email": "me@evertpot.com", "homepage": "http://evertpot.com/", "role": "Developer" } ], "support": { "forum": "https://groups.google.com/group/sabredav-discuss", "source": "https://github.com/fruux/sabre-uri" }, "autoload": { "files" : [ "lib/functions.php" ], "psr-4" : { "Sabre\\Uri\\" : "lib/" } }, "require-dev": { "sabre/cs": "~0.0.1", "phpunit/phpunit" : "*" }, "config" : { "bin-dir" : "bin/" } } sabre-uri-1.0.1/lib/000077500000000000000000000000001252005211600141425ustar00rootroot00000000000000sabre-uri-1.0.1/lib/Version.php000066400000000000000000000005301252005211600162760ustar00rootroot00000000000000 '80', 'https' => '443', ]; if (!empty($parts['port']) && isset($defaultPorts[$parts['scheme']]) && $defaultPorts[$parts['scheme']] == $parts['port']) { // Removing default ports. unset($parts['port']); } // A few HTTP specific rules. switch($parts['scheme']) { case 'http' : case 'https' : if (empty($parts['path'])) { // An empty path is equivalent to / in http. $parts['path'] = '/'; } break; } } if ($parts['host']) $parts['host'] = strtolower($parts['host']); return build($parts); } /** * Parses a URI and returns its individual components. * * This method largely behaves the same as PHP's parse_url, except that it will * return an array with all the array keys, including the ones that are not * set by parse_url, which makes it a bit easier to work with. * * @param string $uri * @return array */ function parse($uri) { return parse_url($uri) + [ 'scheme' => null, 'host' => null, 'path' => null, 'port' => null, 'user' => null, 'query' => null, 'fragment' => null, ]; } /** * This function takes the components returned from PHP's parse_url, and uses * it to generate a new uri. * * @param array $parts * @return string */ function build(array $parts) { $uri = ''; $authority = ''; if (!empty($parts['host'])) { $authority = $parts['host']; if (!empty($parts['user'])) { $authority = $parts['user'] . '@' . $authority; } if (!empty($parts['port'])) { $authority = $authority . ':' . $parts['port']; } } if (!empty($parts['scheme'])) { // If there's a scheme, there's also a host. $uri = $parts['scheme'] . ':'; } if ($authority) { // No scheme, but there is a host. $uri .= '//' . $authority; } if (!empty($parts['path'])) { $uri .= $parts['path']; } if (!empty($parts['query'])) { $uri .= '?' . $parts['query']; } if (!empty($parts['fragment'])) { $uri .= '#' . $parts['fragment']; } return $uri; } /** * Returns the 'dirname' and 'basename' for a path. * * The reason there is a custom function for this purpose, is because * basename() is locale aware (behaviour changes if C locale or a UTF-8 locale * is used) and we need a method that just operates on UTF-8 characters. * * In addition basename and dirname are platform aware, and will treat * backslash (\) as a directory separator on windows. * * This method returns the 2 components as an array. * * If there is no dirname, it will return an empty string. Any / appearing at * the end of the string is stripped off. * * @param string $path * @return array */ function split($path) { $matches = []; if(preg_match('/^(?:(?:(.*)(?:\/+))?([^\/]+))(?:\/?)$/u', $path, $matches)) { return [$matches[1], $matches[2]]; } return [null,null]; } sabre-uri-1.0.1/tests/000077500000000000000000000000001252005211600145365ustar00rootroot00000000000000sabre-uri-1.0.1/tests/BuildTest.php000066400000000000000000000015311252005211600171460ustar00rootroot00000000000000assertEquals( $value, build(parse_url($value)) ); } function buildUriData() { return [ [ 'http://example.org/'], [ 'http://example.org/foo/bar'], [ '//example.org/foo/bar'], [ '/foo/bar'], [ 'http://example.org:81/'], [ 'http://user@example.org:81/'], [ 'http://example.org:81/hi?a=b'], [ 'http://example.org:81/hi?a=b#c=d'], // [ '//example.org:81/hi?a=b#c=d'], // Currently fails due to a // PHP bug. [ '/hi?a=b#c=d'], [ '?a=b#c=d'], [ '#c=d'], ]; } } sabre-uri-1.0.1/tests/NormalizeTest.php000066400000000000000000000022561252005211600200540ustar00rootroot00000000000000assertEquals( $out, normalize($in) ); } function normalizeData() { return [ [ 'http://example.org/', 'http://example.org/' ], [ 'HTTP://www.EXAMPLE.com/', 'http://www.example.com/'], [ 'http://example.org/%7Eevert', 'http://example.org/~evert'], [ 'http://example.org/./evert', 'http://example.org/evert'], [ 'http://example.org/../evert', 'http://example.org/evert'], [ 'http://example.org/foo/../evert', 'http://example.org/evert'], [ '/%41', '/A'], [ '/%3F', '/%3F'], [ '/%3f', '/%3F'], [ 'http://example.org', 'http://example.org/'], [ 'http://example.org:/', 'http://example.org/'], [ 'http://example.org:80/', 'http://example.org/'], ]; } } sabre-uri-1.0.1/tests/ResolveTest.php000066400000000000000000000041011252005211600175220ustar00rootroot00000000000000assertEquals( $expected, resolve($base, $update) ); } function resolveData() { return [ [ 'http://example.org/foo/baz', '/bar', 'http://example.org/bar', ], [ 'https://example.org/foo', '//example.net/', 'https://example.net/', ], [ 'https://example.org/foo', '?a=b', 'https://example.org/foo?a=b', ], [ '//example.org/foo', '?a=b', '//example.org/foo?a=b', ], // Ports and fragments [ 'https://example.org:81/foo#hey', '?a=b#c=d', 'https://example.org:81/foo?a=b#c=d', ], // Relative.. in-directory paths [ 'http://example.org/foo/bar', 'bar2', 'http://example.org/foo/bar2', ], // Now the base path ended with a slash [ 'http://example.org/foo/bar/', 'bar2/bar3', 'http://example.org/foo/bar/bar2/bar3', ], // .. and . [ 'http://example.org/foo/bar/', '../bar2/.././/bar3/', 'http://example.org/foo//bar3/', ], // Only updating the fragment [ 'https://example.org/foo?a=b', '#comments', 'https://example.org/foo?a=b#comments', ], // Switching to mailto! [ 'https://example.org/foo?a=b', 'mailto:foo@example.org', 'mailto:foo@example.org', ], ]; } } sabre-uri-1.0.1/tests/SplitTest.php000066400000000000000000000024131252005211600172020ustar00rootroot00000000000000 ['/foo','bar'], '/foo/bar/' => ['/foo','bar'], 'foo/bar/' => ['foo','bar'], 'foo/bar' => ['foo','bar'], 'foo/bar/baz' => ['foo/bar','baz'], 'foo/bar/baz/' => ['foo/bar','baz'], 'foo' => ['','foo'], 'foo/' => ['','foo'], '/foo/' => ['','foo'], '/foo' => ['','foo'], '' => [null,null], // UTF-8 "/\xC3\xA0fo\xC3\xB3/bar" => ["/\xC3\xA0fo\xC3\xB3",'bar'], "/\xC3\xA0foo/b\xC3\xBCr/" => ["/\xC3\xA0foo","b\xC3\xBCr"], "foo/\xC3\xA0\xC3\xBCr" => ["foo","\xC3\xA0\xC3\xBCr"], ]; foreach($strings as $input => $expected) { $output = split($input); $this->assertEquals($expected, $output, 'The expected output for \'' . $input . '\' was incorrect'); } } } sabre-uri-1.0.1/tests/phpcs/000077500000000000000000000000001252005211600156535ustar00rootroot00000000000000sabre-uri-1.0.1/tests/phpcs/ruleset.xml000066400000000000000000000036421252005211600200650ustar00rootroot00000000000000 sabre.io codesniffer ruleset sabre-uri-1.0.1/tests/phpunit.xml.dist000066400000000000000000000006471252005211600177200ustar00rootroot00000000000000 . ../lib/