mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Handle partially encoded url query strings in request node
This commit is contained in:
parent
a9bc111c4f
commit
f1775d4fd1
@ -134,7 +134,29 @@ in your Node-RED user directory (${RED.settings.userDir}).
|
||||
url = "http://"+url;
|
||||
}
|
||||
}
|
||||
url = encodeURI(url);
|
||||
|
||||
// The Request module used in Node-RED 1.x was tolerant of query strings that
|
||||
// were partially encoded. For example - "?a=hello%20there&b=20%"
|
||||
// The GOT module doesn't like that.
|
||||
// The following is an attempt to normalise the url to ensure it is properly
|
||||
// encoded. We cannot just encode it directly as we don't want any valid
|
||||
// encoded entity to end up doubly encoded.
|
||||
if (url.indexOf("?") > -1) {
|
||||
// Only do this if there is a query string to deal with
|
||||
const [hostPath, ...queryString] = url.split("?")
|
||||
const query = queryString.join("?");
|
||||
if (query) {
|
||||
// Look for any instance of % not followed by two hex chars.
|
||||
// Replace any we find with %25.
|
||||
const escapedQueryString = query.replace(/(%.?.?)/g, function(v) {
|
||||
if (/^%[a-f0-9]{2}/i.test(v)) {
|
||||
return v;
|
||||
}
|
||||
return v.replace(/%/,"%25")
|
||||
})
|
||||
url = hostPath+"?"+escapedQueryString;
|
||||
}
|
||||
}
|
||||
|
||||
var method = nodeMethod.toUpperCase() || "GET";
|
||||
if (msg.method && n.method && (n.method !== "use")) { // warn if override option not set
|
||||
|
@ -1145,7 +1145,7 @@ describe('HTTP Request Node', function() {
|
||||
try {
|
||||
msg.should.have.property('payload',{
|
||||
query:{ a: 'b', c:[ 'T24,0°|H80%|W S8,3m/s' ] },
|
||||
url: '/getQueryParams?a=b&c%5B0%5D.Text=T24,0%C2%B0%7CH80%25%7CW%20S8,3m/s'
|
||||
url: '/getQueryParams?a=b&c[0].Text=T24,0%C2%B0|H80%25|W%20S8,3m/s'
|
||||
});
|
||||
msg.should.have.property('statusCode',200);
|
||||
msg.should.have.property('headers');
|
||||
@ -1154,7 +1154,7 @@ describe('HTTP Request Node', function() {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
n1.receive({url: getTestURL('/getQueryParams')+"?a=b&c[0].Text=T24,0°|H80%|W S8,3m/s"});
|
||||
n1.receive({url: getTestURL('/getQueryParams')+"?a=b&c[0].Text=T24,0°|H80%|W%20S8,3m/s"});
|
||||
});
|
||||
})
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user