Node: querystring should maybe support Buffers

Created on 15 Jan 2017  路  3Comments  路  Source: nodejs/node

  • Version: N/A
  • Platform: N/A
  • Subsystem: querystring

This was reported on IRC by zzo38 who doesn鈥檛 have a github account, so I鈥檓 opening this issue for them.

require("querystring").escape(Buffer.from([0x80,0x81])) is expecting %80%81 but results %EF%BF%BD%EF%BF%BD

So I鈥檓 reading this as requesting support in querystring.escape (and maybe querystring.unescape) for raw encoding/decoding to Buffer instances instead of always interpreting the values as UTF-8 strings.

feature request querystring

Most helpful comment

@jasnell Buffer.from([0x80,0x80]).toString() gives you 锟斤拷, and querystring.escape basically converts that back to <Buffer ef bf bd ef bf bd> and then returns %EF%BF%BD%EF%BF%BD.

I can see why one would expect Buffer.from([0x80,0x81]) to result in %80%81, but I share the -0 stance given that it is pretty feasible to do this in userland already. (e.g. as buf.toString('hex').replace(/../g, e => `%${e}`))

All 3 comments

I'm -0 on this. Calling require('querystring').escape(Bufer.from([0x80,0x80]).toString()) is not that difficult a thing to do and I'd rather not touch the existing querystring/URL code more than necessary.

@jasnell Buffer.from([0x80,0x80]).toString() gives you 锟斤拷, and querystring.escape basically converts that back to <Buffer ef bf bd ef bf bd> and then returns %EF%BF%BD%EF%BF%BD.

I can see why one would expect Buffer.from([0x80,0x81]) to result in %80%81, but I share the -0 stance given that it is pretty feasible to do this in userland already. (e.g. as buf.toString('hex').replace(/../g, e => `%${e}`))

I鈥檓 closing this as something that can be achieved in userland. If somebody disagrees, feel free to re-open or open another issue or whatever makes the most sense to you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

akdor1154 picture akdor1154  路  3Comments

fanjunzhi picture fanjunzhi  路  3Comments

filipesilvaa picture filipesilvaa  路  3Comments

srl295 picture srl295  路  3Comments

loretoparisi picture loretoparisi  路  3Comments