diff options
author | tailor <cygnus@janrain.com> | 2008-05-21 00:16:11 +0000 |
---|---|---|
committer | tailor <cygnus@janrain.com> | 2008-05-21 00:16:11 +0000 |
commit | 2c76c6e422aa6c57d6446e069ba4c1aabc7c1c4e (patch) | |
tree | efb2ab216e2ad03302ae321106f37fefe3b72cba /Auth | |
parent | 3c17f38b75127257dac28ea86c674ae0f2426da6 (diff) | |
download | php-openid-2c76c6e422aa6c57d6446e069ba4c1aabc7c1c4e.zip php-openid-2c76c6e422aa6c57d6446e069ba4c1aabc7c1c4e.tar.gz php-openid-2c76c6e422aa6c57d6446e069ba4c1aabc7c1c4e.tar.bz2 |
[project @ Actually use URINorm functionality for Auth_OpenID::normalizeURL]
Diffstat (limited to 'Auth')
-rw-r--r-- | Auth/OpenID.php | 61 | ||||
-rw-r--r-- | Auth/OpenID/Discover.php | 12 |
2 files changed, 14 insertions, 59 deletions
diff --git a/Auth/OpenID.php b/Auth/OpenID.php index ab0b621..f5d559c 100644 --- a/Auth/OpenID.php +++ b/Auth/OpenID.php @@ -23,6 +23,7 @@ require_once "Auth/Yadis/PlainHTTPFetcher.php"; require_once "Auth/Yadis/ParanoidHTTPFetcher.php"; require_once "Auth/OpenID/BigMath.php"; +require_once "Auth/OpenID/URINorm.php"; /** * Status code returned by the server when the only option is to show @@ -437,62 +438,28 @@ class Auth_OpenID { */ function normalizeUrl($url) { - if ($url === null) { - return null; - } - - assert(is_string($url)); - - $old_url = $url; - $url = trim($url); - - if (strpos($url, "://") === false) { - $url = "http://" . $url; - } - - $parsed = @parse_url($url); + @$parsed = parse_url($url); - if ($parsed === false) { + if (!$parsed) { return null; } - $defaults = array( - 'scheme' => '', - 'host' => '', - 'path' => '', - 'query' => '', - 'fragment' => '', - 'port' => '' - ); - - $parsed = array_merge($defaults, $parsed); - - if (($parsed['scheme'] == '') || - ($parsed['host'] == '')) { - if ($parsed['path'] == '' && - $parsed['query'] == '') { + if (isset($parsed['scheme']) && + isset($parsed['host'])) { + $scheme = strtolower($parsed['scheme']); + if (!in_array($scheme, array('http', 'https'))) { return null; } - - $url = 'http://' + $url; - $parsed = parse_url($url); - - $parsed = array_merge($defaults, $parsed); + } else { + $url = 'http://' . $url; } - $tail = array_map(array('Auth_OpenID', 'quoteMinimal'), - array($parsed['path'], - $parsed['query'])); - if ($tail[0] == '') { - $tail[0] = '/'; + $normalized = Auth_OpenID_urinorm($url); + if ($normalized === null) { + return null; } - - $url = Auth_OpenID::urlunparse($parsed['scheme'], $parsed['host'], - $parsed['port'], $tail[0], $tail[1]); - - assert(is_string($url)); - - return $url; + list($defragged, $frag) = Auth_OpenID::urldefrag($normalized); + return $defragged; } /** diff --git a/Auth/OpenID/Discover.php b/Auth/OpenID/Discover.php index b8f4d56..4e8e402 100644 --- a/Auth/OpenID/Discover.php +++ b/Auth/OpenID/Discover.php @@ -454,18 +454,6 @@ function Auth_OpenID_discoverWithYadis($uri, &$fetcher, function Auth_OpenID_discoverURI($uri, &$fetcher) { - $parsed = parse_url($uri); - - if ($parsed && isset($parsed['scheme']) && - isset($parsed['host'])) { - if (!in_array($parsed['scheme'], array('http', 'https'))) { - // raise DiscoveryFailure('URI scheme is not HTTP or HTTPS', None) - return array($uri, array()); - } - } else { - $uri = 'http://' . $uri; - } - $uri = Auth_OpenID::normalizeUrl($uri); return Auth_OpenID_discoverWithYadis($uri, $fetcher); } |