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

Bug #17036 Problem with parsed query string
Submitted: 2010-01-26 15:48 UTC Modified: 2011-03-14 14:15 UTC
From: lukas Assigned: till
Status: Closed Package: Net_URL2 (version 0.3.1)
PHP Version: 5.1.3 OS: linux
Roadmaps: (Not assigned)    
Subscription  


 [2010-01-26 15: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>'); ?>

Comments

 [2010-01-26 15:55 UTC] lukas (Lukas Emile)
-Summary: Problem with query string parsed +Summary: Problem with parsed query string
 [2010-01-26 16: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 17:19 UTC] schmidt (Christian Schmidt)
True, this is a bug.
 [2010-02-03 15:57 UTC] lukas (Lukas Emile)
 [2010-02-03 15: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 17:12 UTC] schmidt (Christian Schmidt)
The patch does not respect the various OPTION_xxx options.
 [2011-03-13 02:49 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 13: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. http://svn.php.net/viewvc?view=revision&revision=309168 Wouldn't mind if ANYONE could take a look so this is finished and we can move on a new release.
 [2011-03-14 08:50 UTC] cweiske (Christian Weiske)
Yes, your patch fixes the problem.
 [2011-03-14 14: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 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. Epic win!!!11