8

Is there any option for qs.stringify that will not encode the urls?

$ node
> var qs = require("querystring");
undefined
> qs.stringify({"url": "http://domain.com"});
'url=http%3A%2F%2Fdomain.com'

I want the folowing output:

'url=http://domain.com'
2
  • 2
    This begs a good question: Why? That's not a valid query-string, which is why they're encoded. Commented Aug 28, 2013 at 19:18
  • 2
    @JonathanLonowski I use youtube api and I got an error. I thought that the problem was the encoding of the url, but it wasn't... The problem was that I forgot response_type parameter. :-) Anyway, thanks! Commented Aug 29, 2013 at 4:36

5 Answers 5

6

It's a little late, but for the next person, you can do: querystring.unescape(myString)

Sign up to request clarification or add additional context in comments.

1 Comment

Just remember that this will also unescape everything else, so %20 will be rendered into ` ` (a literal space) and so on...
6

Late answer again, but...
qs.stringify() has option encode:false which actually disable the URI encoding.

Qs.stringify documentation

You can also use it in nodejs request/request module as:

request({
  url: 'http://url.domain'
  qs: {
    qs1: 'thisIsNotEncodedInTheRequest%20://асд'
  },
  qsStringifyOptions: {
    // encoding: false /** (OLD VERSION - I think is deprecated yet) */
    encode: false
  }
});

2 Comments

It appears to have changed, or always was, to encode as opposed to encoding. So encode: false
3

Not directly, no. Although, if you are not escaping the value in the query string then there is hardly any benefit to using querystring at all. Mind as well just do: var q = 'url=http://domain.com'

EDIT: From looking at the source, the only way would be to change the behavior of (i.e. overwrite) the querystring escape() function - which is possible but not a good idea.

Comments

1

Here is the answer:

qs.stringify({url: "http://domain.com"}, { encodeURIComponent: uri => uri });

The option "encodeURIComponent: uri => uri" is to disable the encoding.

1 Comment

It still does not work with browserify github.com/mike-spainhower/querystring/issues/4
0

This worked for me

qs.stringify({url: "http://example.com"}, null, null, { encodeURIComponent: qs.unescape });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.