Superagent: Incorrect encoding of characters in query parameters

Created on 25 Jun 2015  路  2Comments  路  Source: visionmedia/superagent

Superagent runs encodeURIComponent on all query keys. However, RFC3986 defines a number of characters (sub-delims) which may be used unencoded in the query part of a url, including comma and a few more like +'!$()*;.

This means you can't use superagent to query a valid url like /id?key=val1,val2.

It also means superagent is incompatible with a lot of other url software like curl, chrome, python-requests and npm request.

This should be documented. Ideally, superagent should leave encoding to the user, although this would be a breaking change. Or, have an option to disable encoding.

Most helpful comment

I believe you can disable encoding by passing a full query string to .query instead of an object.

All 2 comments

I believe you can disable encoding by passing a full query string to .query instead of an object.

You're right, this works as expected:

request
  .get('http://localhost/id')
  .query('key=val1,val2')
  .end(function(err, res) {
    console.log(res.text);
});

Thanks for the workaround.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

djizco picture djizco  路  5Comments

tj picture tj  路  4Comments

noway picture noway  路  4Comments

tj picture tj  路  9Comments

t3hmrman picture t3hmrman  路  9Comments