puritys / nodejs-phplike

Porting PHP to Node.js
http://www.puritys.me/docs-blog/article-201
33 stars 12 forks source link

http_build_query does not encode square brackets #8

Closed jhorbulyk closed 7 years ago

jhorbulyk commented 7 years ago

Consider the following PHP code:

$params = [
    'foo' => [
        [
            'bar' => 'baz',
            'operator' => '>'
        ]
    ]
];
print(http_build_query($params));

The output is: foo%5B0%5D%5Bbar%5D=baz&foo%5B0%5D%5Boperator%5D=%3E which decodes to foo[0][bar]=baz&foo[0][operator]=>

Consider the following JS code:

var http_build_query = require('phplike/module.js').http_build_query;
var params = {
    foo: [
        {bar:'baz', operator: '>'}    
    ]
};
console.log(http_build_query(params));

The result is foo[0][bar]=baz&foo[0][operator]=%3E which matches neither the pre or post encoded values for the php function.

Is this a bug which should be fixed?

puritys commented 7 years ago

New version phplike@2.5.5