-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Unable to override QueryString.unescape #4055
Comments
Are you sure this action won't break any other libraries? I'd really suggest to clone querystring.js and make appropriate changes there using it as your own module... |
Can someone review bnoordhuis/node@9a7b6c0? It adds a decodeSpaces option to querystring.parse(). |
@bnoordhuis @rlidwka Nothing to review. Test case is attached. Is there any standard to compare with? |
@bnoordhuis, addition of the decodeSpaces option LGTM. But I think the real issue here is that overriding
Looking at the code... It's apparent that IMO we should either: eliminate the calls to QueryString.unescape = function(s, decodeSpaces) {
if (!decodeSpaces) {
try {
return decodeURIComponent(s);
} catch (e) { }
}
return QueryString.unescapeBuffer(s, decodeSpaces).toString()
}; ...either way, the effect is that |
Actually, I think it's pretty silly that we suggest to monkey-patch a global function, I don't know why that was ever added to the docs. I'm going to remove that unless someone speaks up. |
I don't know about those other guys and their thread hijacking, but my initial request doesn't seem all that unreasonable. I get that you didn't intend for the function to be overrideable in the first place, so take that out of the docs. But then why even have that decodeSpaces parameter on the unescapeBuffer function in the first place? You have that try catch setup to use decodeURIComponent first, which doesn't touch a + symbol then you have the second catch function that does. I believe that is a bit inconsistent behavior, to ONLY decode the + if there is an exception in the first try? I can't stand that we have to put this hack into javascript to fix problems with PHP and others that use a stupid + to encode a space! According to http://www.ietf.org/rfc/rfc3986.txt section 2.2, the "+" symbol is reserved and thus should not be touched when decoding... unless im totally reading that wrong... |
Either way this can just be closed, ive worked around this by double encoding all my values that might contain a + |
@bnoordhuis +1 for the doc change. good call. I, too, was surprised to find that we "decode"
Might be a good idea to make a note of these points in the documentation. In lieu of explicit docs, I think most folks would assume that decoding follows the same rules as |
Documentation states that `querystring.unescape` may be overridden to replace unescaper during parsing. However, the function was only being used as a fallback for when the native decoder throws (on a malformed URL). This patch moves the call to the native function and the try/catch around it into querystring.unescape then has the parser always invoke it, so that an override will always be used. Fixes nodejs#4055 Reviewed-By: Fedor Indutny <fedor@indutny.com>
var querystring = require('querystring');
querystring.unescape = function(a,b) { console.log('unescape no more'); }
querystring.parse('t=asdf&u=john+nelson@gmail.com');
The main thing that im trying to do is NOT have the + replaced with a space, the only apparent way to do that is to override unescape.
let me know if there is a way to do this as its just not working for me.
thanks
The text was updated successfully, but these errors were encountered: