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

Bug #16050 URL generation problem with query parameters
Submitted: 2009-03-21 00:36 UTC
From: ciarang Assigned: kguest
Status: Closed Package: Net_URL_Mapper (version 0.9.0)
PHP Version: Irrelevant OS: Etch
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 16 + 2 = ?

 
 [2009-03-21 00:36 UTC] ciarang (Ciaran Gultnieks)
Description: ------------ If you match a URL that contains a query string, then supply additional parameters when attempting to generate a new URL, the generator doesn't take into account the existing parameters and so incorrectly adds a '?' where an '&' is required. For example, match: connect('search/notice?q=:q', array('action' => 'noticesearch'),array('q' => '.+')); Then pass the following into generate(): $args - ( [action] => noticesearch, [q] => x) $params - ([p] => 1 ) Instead of getting back "/search/notice?q=x&p=1" you get the invalid "/search/notice?q=x?p=1". Test script: --------------- This fixes it... --- a/extlib/Net/URL/Mapper/Path.php +++ b/extlib/Net/URL/Mapper/Path.php @@ -241,7 +241,12 @@ class Net_URL_Mapper_Path } $path = '/'.trim(Net_URL::resolvePath($path), '/'); if (!empty($qstring)) { - $path .= '?'.http_build_query($qstring); + if (!strpos($path, '?')) { + $path .= '?'; + } else { + $path .= '&'; + } + $path .= http_build_query($qstring); } if (!empty($anchor)) { $path .= '#'.ltrim($anchor, '#');

Comments

 [2010-03-20 05:36 UTC] kguest (Ken Guest)
-Assigned To: +Assigned To: kguest
 [2010-03-20 05:36 UTC] kguest (Ken Guest)
-Status: Assigned +Status: Closed
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.