handle multi-line base64 strings

This commit is contained in:
Dave Conway-Jones 2017-09-07 10:28:52 +01:00
parent e61da83d5d
commit 8b53d09ad3
No known key found for this signature in database
GPG Key ID: 81B04231572A9A2D
2 changed files with 5 additions and 4 deletions

View File

@ -14,9 +14,10 @@ module.exports = function(RED) {
}
else if (typeof msg.payload === "string") {
// Take base64 string and make into binary buffer
var regexp = new RegExp('^[A-Za-z0-9+\/=]*$');
if ( regexp.test(msg.payload) && (msg.payload.length % 4 === 0) ) {
msg.payload = new Buffer(msg.payload,'base64');
var load = msg.payload.replace(/\s+/g,''); // remove any whitespace
var regexp = new RegExp('^[A-Za-z0-9+\/=]*$'); // check it only contains valid characters
if ( regexp.test(load) && (load.length % 4 === 0) ) {
msg.payload = new Buffer(load,'base64');
node.send(msg);
}
else {

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-base64",
"version" : "0.0.6",
"version" : "0.0.7",
"description" : "A Node-RED node to pack and unpack objects to base64 format",
"dependencies" : {
},