Source code for file /openid/Auth/OpenID/URINorm.php
Documentation is available at URINorm.php
* URI normalization routines.
* @copyright 2005 Janrain, Inc.
* @license http://www.gnu.org/copyleft/lesser.html LGPL
require_once 'Services/Yadis/Misc.php';
// from appendix B of rfc 3986 (http://www.ietf.org/rfc/rfc3986.txt)
$__uri_pattern =
'&^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?&';
$__authority_pattern =
'/^([^@]*@)?([^:]*)(:.*)?/';
$__pct_encoded_pattern =
'/%([0-9A-Fa-f]{2})/';
for ($i =
0; $i <
256; $i++
) {
$_unreserved[$i] =
false;
for ($i =
ord('A'); $i <=
ord('Z'); $i++
) {
for ($i =
ord('0'); $i <=
ord('9'); $i++
) {
for ($i =
ord('a'); $i <=
ord('z'); $i++
) {
$_unreserved[ord('-')] =
true;
$_unreserved[ord('.')] =
true;
$_unreserved[ord('_')] =
true;
$_unreserved[ord('~')] =
true;
foreach (array_merge($__UCSCHAR, $__IPRIVATE) as $pair) {
$result_segments =
array();
} else if ($path ==
'/.') {
} else if ($path ==
'/..') {
} else if (($path ==
'..') ||
$result_segments[] =
substr($path, 0, $i);
return implode('', $result_segments);
global $__uri_pattern, $__authority_pattern, $__pct_encoded_pattern;
if (count($uri_matches) <
9) {
for ($i =
count($uri_matches); $i <=
9; $i++
) {
$scheme =
$uri_matches[2];
$scheme =
$uri_matches[2];
if (!in_array($scheme, array('http', 'https'))) {
// Not an absolute HTTP or HTTPS URI
$authority =
$uri_matches[4];
$authority_matches =
array();
preg_match($__authority_pattern, $authority, $authority_matches);
if (count($authority_matches) ===
0) {
// URI does not have a valid authority
if (count($authority_matches) <
4) {
for ($i =
count($authority_matches); $i <=
4; $i++
) {
$authority_matches[] =
'';
list
($_whole, $userinfo, $host, $port) =
$authority_matches;
if ($userinfo ===
null) {
if (strpos($host, '%') !== -
1) {
$__pct_encoded_pattern, '_pct_encoded_replace', $host);
// $host = unicode($host, 'utf-8').encode('idna');
($scheme ==
'http' &&
$port ==
':80') ||
($scheme ==
'https' &&
$port ==
':443')) {
$authority =
$userinfo .
$host .
$port;
'_pct_encoded_replace_unreserved', $path);
$query =
$uri_matches[6];
$fragment =
$uri_matches[8];
if ($fragment ===
null) {
return $scheme .
'://' .
$authority .
$path .
$query .
$fragment;