|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36656 http_build_query generates invalid URIs due to use of square brackets
Submitted: 2006-03-08 16:18 UTC Modified: 2006-03-08 23:08 UTC
From: php at colin dot guthr dot ie Assigned:
Status: Closed Package: *URL Functions
PHP Version: 5.1.2 OS: Linux 2.6.12
Private report: No CVE-ID: None
 [2006-03-08 16:18 UTC] php at colin dot guthr dot ie
According to RFC3986, which I beleive to be the latest in a long line of RFCs on URI syntaxt, it is illegal to use square brackets in the search string.

There is a comment on the PHP manual page for rawurlencode that states that these are now permitted but extensive RFC reading and googling fails to back this up for me.

From what I can gather they should be encoded as %5B and %5D.

Here is the pseudo fix: str_replace(array('[',']'), array('%5B','%5D'), http_build_query(array('hello' => array('interesting','eh'))))

The fix is quite simple and some small changes need to be made to http.c - I've not got a patch unfortunatly, but it should only take a short while to fix and would probably take just as long as a patch review ;)

Reproduce code:
echo http_build_query(array('hello' => array('interesting','eh')))."\n";

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-08 23:08 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun May 28 15:03:42 2023 UTC