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

Bug #17036 Problem with parsed query string
Submitted: 2010-01-26 20:48 UTC
From: lukas Assigned: tkli
Status: Closed Package: Net_URL2 (version 0.3.1)
PHP Version: 5.1.3 OS: linux
Roadmaps: (Not assigned)    

 [2010-01-26 20:48 UTC] lukas (Lukas Emile)
Description: ------------ (sorry for my english) hi, there is a problem with the result of Net_URL2::getQueryVariables(). Variables aren't treated recursively. so Net_URL2::getQueryVariables() could be : public function getQueryVariables() { $return = array(); if ($this->_query !== false) { parse_str($this->_query, $return); } return $return; } and Net_URL2::setQueryVariables() could be : public function setQueryVariables(array $array) { $this->_query = http_build_query($array); } and Net_URL2::setQueryVariable($name, $value) : public function setQueryVariable($name, $value) { $keys = preg_split('/[\[\]]+/', $name); $array = $vars = $this->getQueryVariables(); foreach ($keys as $key) { if (!array_key_exists($key, $var) { $var[$key] = array(); } $var =& $var[$key]; } $var = $value; $this->setQueryVariables($array); } I don't have tested setters methods, but it could be something like than. The given code display the differnce between methods. Test script: --------------- <?php require_once 'Var_Dump.php'; require_once 'Net/URL2.php'; Var_Dump::displayInit(array('display_mode' => 'HTML4_Table')); $url = new Net_URL2('?start=10&test[0][first][1.1][20]=coucou'); $vars = array(); parse_str($url->getQuery(), $vars); exit('<pre>$url => '.Var_Dump::display('new Net_URL2("?start=10&test[0][first][1.1][20]=coucou");', true).' $url->getQuery() => '.Var_Dump::display($url->getQuery(), true).' parse_str() => '.Var_Dump::display($vars, true).' $url->getQueryVariables() => '.Var_Dump::display($url->getQueryVariables(), true).' $_GET => '.Var_Dump::display($_GET, true).'</pre>'); ?>


 [2010-01-26 20:55 UTC] lukas (Lukas Emile)
-Summary: Problem with query string parsed +Summary: Problem with parsed query string
 [2010-01-26 21:09 UTC] lukas (Lukas Emile)
modification : public function setQueryVariable($name, $value) { $keys = preg_split('/[\[\]]+/', trim($name, '[]')); $array = $this->getQueryVariables(); $var =& $array; foreach ($keys as $key) { if (!array_key_exists($key, $var)) { $var[$key] = array(); } $var =& $var[$key]; } $var = $value; $this->setQueryVariables($array); }
 [2010-01-28 22:19 UTC] schmidt (Christian Schmidt)
True, this is a bug.
 [2010-02-03 20:57 UTC] lukas (Lukas Emile)
 [2010-02-03 20:58 UTC] lukas (Lukas Emile)
I've maid a patch. The script use parse_str and http_build_query instead of foreach and explode functions.
 [2010-02-08 22:12 UTC] schmidt (Christian Schmidt)
The patch does not respect the various OPTION_xxx options.
 [2011-03-13 07:00 UTC] till (Till Klampaeckel)
-Status: Open +Status: Feedback -Assigned To: +Assigned To: till
Lukas, you mind providing some example code which I could wrap into a unit test? Till
 [2011-03-13 17:39 UTC] till (Till Klampaeckel)
I think this might have been fixed by another bugfix I did. Anyway, I tried to make sense of the example code and committed a unit test with it. The unit test runs. Wouldn't mind if ANYONE could take a look so this is finished and we can move on a new release.
 [2011-03-14 12:50 UTC] cweiske (Christian Weiske)
Yes, your patch fixes the problem.
 [2011-03-14 18:15 UTC] till (Till Klampaeckel)
-Status: Feedback +Status: Closed
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on by the end of next Sunday (CET). If this was a problem with the 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. Epic win!!!11
 [2014-01-02 02:40 UTC] tkli (Tom Klingenberg)
-Status: Closed +Status: Open -Assigned To: till +Assigned To: tkli
This was not fixed that time despite the test result might have made it look that way. The problem with the test is, that it is not testing Net_URL2::getQueryVariables(). The test only tests PHPs built-in function parse_str(). Therefore the Net_URL2Test::testQueryVariables() is bogus. This has come to my attention while reviewing the regex patterns in getQueryVariables() recently which made me assume a flaw due to greedy matching. Next release 2.0.5 will have this fixed.
 [2014-01-02 04:37 UTC] tkli (Tom Klingenberg)
-Status: Assigned +Status: Closed
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at So better late then never :) Now fixed in 2.0.5.
 [2014-01-02 06:09 UTC] tkli (Tom Klingenberg)
Some notes from the commit for details: Brackets are now properly parsed. In difference to PHPs own variant, Net_URL2::getQueryVariables is binary safe and does allow spaces and dots as well as null-characters in both key-names (variables) as well as array-keys - both url- encoded or url-decoded.