diff options
-rw-r--r-- | Auth/OpenID.php | 14 | ||||
-rw-r--r-- | Tests/Auth/OpenID/Util.php | 23 |
2 files changed, 35 insertions, 2 deletions
diff --git a/Auth/OpenID.php b/Auth/OpenID.php index 9582f50..c74c252 100644 --- a/Auth/OpenID.php +++ b/Auth/OpenID.php @@ -381,7 +381,7 @@ class Auth_OpenID { } if (!$path) { - $path = '/'; + $path = ''; } $result = $scheme . "://" . $host; @@ -520,6 +520,16 @@ class Auth_OpenID { return $b; } -} + function urldefrag($url) + { + $parts = explode("#", $url, 2); + + if (count($parts) == 1) { + return array($parts[0], ""); + } else { + return $parts; + } + } +} ?>
\ No newline at end of file diff --git a/Tests/Auth/OpenID/Util.php b/Tests/Auth/OpenID/Util.php index de60c92..8e7b009 100644 --- a/Tests/Auth/OpenID/Util.php +++ b/Tests/Auth/OpenID/Util.php @@ -74,6 +74,29 @@ class Tests_Auth_OpenID_Util extends PHPUnit_TestCase { } } + function test_urldefrag() + { + $cases = array( + array('http://foo.com', 'http://foo.com'), + array('http://foo.com/', 'http://foo.com/'), + array('http://foo.com/path', 'http://foo.com/path'), + array('http://foo.com/path?query', 'http://foo.com/path?query'), + array('http://foo.com/path?query=v', 'http://foo.com/path?query=v'), + array('http://foo.com/?query=v', 'http://foo.com/?query=v'), + ); + + foreach ($cases as $pair) { + list($orig, $after) = $pair; + list($base, $frag) = Auth_OpenID::urldefrag($orig); + $this->assertEquals($after, $base); + $this->assertEquals($frag, ''); + + list($base, $frag) = Auth_OpenID::urldefrag($orig . "#fragment"); + $this->assertEquals($after, $base); + $this->assertEquals('fragment', $frag); + } + } + function test_normalizeUrl() { $this->assertEquals("http://foo.com/", |