Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.1.2

Bug #14178 resolvePath Problems
Submitted: 2008-06-18 11:46 UTC
From: tkli Assigned: till
Status: Bogus Package: Net_URL2 (version 0.1.0)
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2008-06-18 11:46 UTC] tkli (Tom Klingenberg)
Description: ------------ I came over this function because I was recherching to write one on my own. The First thing I ran over is $path = explode('/', str_replace('//', '/', $path)); str_replace does not work recursively. It should then be: while (false !== strpos($path,'//')) { $path = str_replace('//', '/', $path); } anyway doing this (or the prior) does break standard URL handling as defined in RFC 1630, see Page 9ff. There is only need to resolve '.' and '..' not ''(empty as between / and / is nothing). This is as all standard Browsers do as well. Additionally it can make sense to add some logic sothat resolvePath does even work on relative Pathes as well. But I do not know if this was intended or not. It is not documented anyway wether it should or not. Since it is a public static function, this should be declared. The Following Examples would be nice to know: * /foo/bar/ => ? * ../foo/bar/../boo.php => ? * /../../../foo/bar/boo.php => ?

Comments

 [2008-06-18 12:06 UTC] schmidt (Christian Schmidt)
Try looking at the latest CVS version. It has a much improved URL resolver that follows the RFC closely and also has support for relative URLs.
 [2008-06-18 13:12 UTC] tkli (Tom Klingenberg)
Okay I see. In case you still have problems in removeDotSegments, here is how I solved it, this info might help or come in handy just ignore if the wording does not fit: /** * Resolve a Path. Handles relative as well * * Example: * * ../foo/bar.php => ../foo/bar.php * /foo/../bar/boo.php => /bar/boo.php * /boo/..//foo//bar.php => //foo//bar.php * /./foo/././bar.php => /foo/bar.php * ./. => ./ * * @param string $path path to resolve * @return string */ public static function resolve_path($path) { $parts = explode('/', $path); $i = 0; $start_fixed = 0; $found_fixed = false; while($i < count($parts)) { $part = $parts[$i]; $o = ($i == $start_fixed) ? 0 : 1; switch ($part) { case '..': // a relative part to resolve case '.' : if ($found_fixed) // check if it is ok to resolve { switch($part) { case '..': array_splice($parts, $i-$o, 1 + $o); break; case '.': array_splice($parts, $i, 1); break; } $i -= $o; } else { $i++; } break; default: // not a relative part, nothing to resolve if (false == $found_fixed) { $found_fixed = true; // something fixed in path found, good! $start_fixed = $i; // fixed part starts here then! } $i++; } } $path = implode('/', $parts); return $path; }
 [2008-06-18 19:35 UTC] schmidt (Christian Schmidt)
I just released version 0.2.0 based on the latest CVS version. Note that it breaks backwards compatibility.
 [2008-07-08 10:01 UTC] doconnor (Daniel O'Connor)
Close -> Fixed in CVS?
 [2008-07-08 10:14 UTC] tkli (Tom Klingenberg)
Just checked the CVS code, the buggy function is still in but I am not a member of this project sothat my suggestions ends here. Adopt the above code or leave it, you can use it freely.
 [2008-07-08 13:42 UTC] schmidt (Christian Schmidt)
I am not sure what problem the mentioned code is trying to solve. Could you please provide a testcase with expected and actual output? removeDotSegments() is a private function, so I assume you are not calling it directly?
 [2008-07-26 02:59 UTC] doconnor (Daniel O'Connor)
A testcase would be really, really handy.
 [2008-10-05 17:57 UTC] doconnor (Daniel O'Connor)
Hey Tom, If you could give us a small executable test case which demonstrates how the current CVS code is broken, that would be great. At the moment, we don't have that, and we don't have a patch in a usable form (see http://wiki.pear.php.net/index.php/BugTriageDay#Making_patches); so it's not too likely any changes would happen. If we've got the executable test script, even someone like me who doesn't know much about the code itself could see the right / wrong behaviour and there is a higher chance your changes would make it in...
 [2011-03-13 09:32 UTC] till (Till Klampaeckel)
-Status: No Feedback +Status: Verified
I committed a unit test for this bug: http://svn.php.net/viewvc?view=revision&revision=309162 I used the examples he provided in his patch. ;-)
 [2011-03-14 19:49 UTC] till (Till Klampaeckel)
-Status: Verified +Status: Bogus -Assigned To: +Assigned To: till
Sorry, but your problem does not imply a bug in PEAR itself. For a list of more appropriate places to ask for help using PEAR, please visit http://pear.php.net/support/ as this bug system is not the appropriate forum for asking support questions. Thank you for your interest in PEAR. I'll bogus this bug, reasons in my commit message: http://svn.php.net/viewvc?view=revision&revision=309226 If anyone has something to add with examples why something doesn't work like they expect, feel free to re-open. I also suggest they look at Net_URL2Test::testResolv().