1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Make the encode option a boolean value to determine whether to encode

This commit is contained in:
Hiroki Uchikawa 2019-02-01 17:15:07 +09:00
parent 7c6eb7c794
commit f3d2053878
2 changed files with 12 additions and 8 deletions

View File

@ -161,9 +161,13 @@ module.exports = function(RED) {
// This case clears a cookie for HTTP In/Response nodes.
// Ignore for this node.
} else if (typeof msg.cookies[name] === 'object') {
// If the encode option is specified, pass it.
var options = msg.cookies[name].encode ? {encode: msg.cookies[name].encode} : undefined;
opts.jar.setCookie(cookie.serialize(name, msg.cookies[name].value, options), url);
if(msg.cookies[name].encode === false){
// If the encode option is false, the value is not encoded.
opts.jar.setCookie(cookie.serialize(name, msg.cookies[name].value, {encode: String}), url);
} else {
// The value is encoded by encodeURIComponent().
opts.jar.setCookie(cookie.serialize(name, msg.cookies[name].value), url);
}
} else {
opts.jar.setCookie(cookie.serialize(name, msg.cookies[name]), url);
}

View File

@ -1106,27 +1106,27 @@ describe('HTTP Request Node', function() {
done(err);
}
});
n1.receive({payload:"foo", cookies:{data:{value:value}}});
n1.receive({payload:"foo", cookies:{data:{value:value, encode:true}}});
});
});
it('should encode cookie by specified function', function(done) {
it('should not encode cookie when encode option is false', function(done) {
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",url:getTestURL('/checkCookie')},
{id:"n2", type:"helper"}];
helper.load(httpRequestNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var value = ',/?:@ &+$#';
var value = '!#$%&\'()*+-./:<>?@[]^_`{|}~';
n2.on("input", function(msg) {
try {
msg.payload.should.have.property('data',encodeURI(value));
msg.payload.should.have.property('data',value);
msg.should.have.property('statusCode',200);
done();
} catch(err) {
done(err);
}
});
n1.receive({payload:"foo", cookies:{data:{value:value,encode:encodeURI}}});
n1.receive({payload:"foo", cookies:{data:{value:value, encode:false}}});
});
});