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:
parent
7c6eb7c794
commit
f3d2053878
@ -161,9 +161,13 @@ module.exports = function(RED) {
|
|||||||
// This case clears a cookie for HTTP In/Response nodes.
|
// This case clears a cookie for HTTP In/Response nodes.
|
||||||
// Ignore for this node.
|
// Ignore for this node.
|
||||||
} else if (typeof msg.cookies[name] === 'object') {
|
} else if (typeof msg.cookies[name] === 'object') {
|
||||||
// If the encode option is specified, pass it.
|
if(msg.cookies[name].encode === false){
|
||||||
var options = msg.cookies[name].encode ? {encode: msg.cookies[name].encode} : undefined;
|
// If the encode option is false, the value is not encoded.
|
||||||
opts.jar.setCookie(cookie.serialize(name, msg.cookies[name].value, options), url);
|
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 {
|
} else {
|
||||||
opts.jar.setCookie(cookie.serialize(name, msg.cookies[name]), url);
|
opts.jar.setCookie(cookie.serialize(name, msg.cookies[name]), url);
|
||||||
}
|
}
|
||||||
|
@ -1106,27 +1106,27 @@ describe('HTTP Request Node', function() {
|
|||||||
done(err);
|
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')},
|
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",url:getTestURL('/checkCookie')},
|
||||||
{id:"n2", type:"helper"}];
|
{id:"n2", type:"helper"}];
|
||||||
helper.load(httpRequestNode, flow, function() {
|
helper.load(httpRequestNode, flow, function() {
|
||||||
var n1 = helper.getNode("n1");
|
var n1 = helper.getNode("n1");
|
||||||
var n2 = helper.getNode("n2");
|
var n2 = helper.getNode("n2");
|
||||||
var value = ',/?:@ &+$#';
|
var value = '!#$%&\'()*+-./:<>?@[]^_`{|}~';
|
||||||
n2.on("input", function(msg) {
|
n2.on("input", function(msg) {
|
||||||
try {
|
try {
|
||||||
msg.payload.should.have.property('data',encodeURI(value));
|
msg.payload.should.have.property('data',value);
|
||||||
msg.should.have.property('statusCode',200);
|
msg.should.have.property('statusCode',200);
|
||||||
done();
|
done();
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
done(err);
|
done(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
n1.receive({payload:"foo", cookies:{data:{value:value,encode:encodeURI}}});
|
n1.receive({payload:"foo", cookies:{data:{value:value, encode:false}}});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user