cvs: docweb /include lib_url_entities.inc.php

From: Date: Tue, 25 Jan 2005 19:37:48 +0000
Subject: cvs: docweb /include lib_url_entities.inc.php
Groups: php.doc.web 
Request: Send a blank email to doc-web+get-567@lists.php.net to get a copy of this message
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 <didou@php.net> | | Sean Coates <sean@php.net> | +----------------------------------------------------------------------+ -$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)

« previous php.doc.web (#567) next »