cvs: docweb /include lib_url_entities.inc.php
[email protected] ("Nuno Lopes")
| Newsgroups | php.doc.web |
|---|---|
| Message-ID | <cvsnlopess1106681868@cvsserver> |
nlopess Tue Jan 25 14:37:48 2005 EDT
Modified files:
/docweb/include lib_url_entities.inc.php
Log:
fix the relative url handling function. Now it passes most RFC 1808 tests
http://cvs.php.net/diff.php/docweb/include/lib_url_entities.inc.php?r1=1.8&r2=1.9&ty=u
Index: docweb/include/lib_url_entities.inc.php
diff -u docweb/include/lib_url_entities.inc.php:1.8 docweb/include/lib_url_entities.inc.php:1.9
--- docweb/include/lib_url_entities.inc.php:1.8 Tue Jan 25 00:42:49 2005
+++ docweb/include/lib_url_entities.inc.php Tue Jan 25 14:37:48 2005
@@ -19,7 +19,7 @@
| Mehdi Achour <[email protected]> |
| Sean Coates <[email protected]> |
+----------------------------------------------------------------------+
-$Id: lib_url_entities.inc.php,v 1.8 2005/01/25 05:42:49 sean Exp $
+$Id: lib_url_entities.inc.php,v 1.9 2005/01/25 19:37:48 nlopess Exp $
*/
// user agent
@@ -108,7 +108,7 @@
}
/**
- * Handles relative HTTP URLs
+ * Handles relative HTTP URLs (almost RFC 1808 compliant)
*
* @param string $url URL to handle
* @param array $parsed result of parse_url()
@@ -124,15 +124,23 @@
return $url;
}
- /* try to be RFC 1808 compliant */
- $path = $parsed['path'] . $url;
+ /* handle ./ and . */
+ if (substr($url, 0, 2) == './') {
+ $url = substr($url, 2);
+ } elseif ($url == '.') {
+ $url = '';
+ }
+
+ $path = dirname($parsed['path']) . "/$url";
$old = '';
+ /* handle ../ */
do {
$old = $path;
- $path = preg_replace('@[^/:?]+/\.\./|\./@S', '', $path);
+ $path = preg_replace('@[^/:?]+/\.\./?@S', '', $path);
} while ($old != $path);
+
return "{$parsed['scheme']}://{$parsed['host']}{$path}";
}
@@ -308,7 +316,7 @@
function ent_value($eVal)
{
- return preg_replace_callback('#(http|ftp)://([^\s]+)#', 'url_callback', $eVal);
+ return preg_replace_callback('#(?:f|ht)tps?://([^\s]+)#S', 'url_callback', $eVal);
}
function ent_link($eVal)