From 0f747da6fec34b13cb7044548c1cc41665050393 Mon Sep 17 00:00:00 2001 From: Evert Pot Date: Mon, 20 Feb 2017 13:25:39 -0500 Subject: [PATCH] Fix for issue #16. Parsing urls that are only a fragment. --- lib/functions.php | 4 ++-- tests/ParseTest.php | 14 ++++++++++++++ tests/ResolveTest.php | 12 ++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/functions.php b/lib/functions.php index df74b98..893ce31 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -333,11 +333,11 @@ function($matches) { } // Taking off a fragment part - if (strpos($uri, '#')) { + if (strpos($uri, '#')!==false) { list($uri, $result['fragment']) = explode('#', $uri, 2); } // Taking off the query part - if (strpos($uri, '?')) { + if (strpos($uri, '?')!==false) { list($uri, $result['query']) = explode('?', $uri, 2); } diff --git a/tests/ParseTest.php b/tests/ParseTest.php index ab0ead2..d797c2c 100644 --- a/tests/ParseTest.php +++ b/tests/ParseTest.php @@ -171,6 +171,20 @@ function parseData() { 'fragment' => null, ] ], + // Parial url + [ + '#foo', + [ + 'scheme' => null, + 'host' => null, + 'path' => null, + 'port' => null, + 'user' => null, + 'query' => null, + 'fragment' => 'foo', + ] + + ] ]; diff --git a/tests/ResolveTest.php b/tests/ResolveTest.php index 73e4dea..5adcd71 100644 --- a/tests/ResolveTest.php +++ b/tests/ResolveTest.php @@ -75,6 +75,18 @@ function resolveData() { 'mailto:foo@example.org', 'mailto:foo@example.org', ], + // Resolving empty path + [ + 'http://www.example.org', + '#foo', + 'http://www.example.org/#foo', + ], + // Another fragment test + [ + 'http://example.org/path.json', + '#', + 'http://example.org/path.json', + ], ];