joomla/joomla-platform — Issue #833: Bug in JURI::buildQuery
Author: ebitester1
Created: 2012-02-07 13:01:41+00:00
State: open

There is an error in JURI::buildQuery in last line:

return urldecode(http_build_query($params, '', '&'));

Using urldecode distort the data if the values ​​in $params array have special characters (& and =).

Example:

$a=array('a'=>array('b'=>array('e'=>123,'f'=>789),'c'=>456), 'd'=>'&h=123');
echo urldecode(http_build_query($a));

Output:

a[b][e]=123&a[b][f]=789&a[c]=456&d=&h=123

You can see a new element h.

I think that urldecode was used for beauty. It was assumed that urldecode will decode the square brackets. However, this function makes more changes!

You can completely remove urldecode. But if you want beauty, you can replace the last line with the following code:

return str_replace(array('%5B', '%5D'), array('[', ']'), http_build_query($params, '', '&'));