Skip to content

Commit 8b53d09

Browse files
author
Dave Conway-Jones
committed
handle multi-line base64 strings
1 parent e61da83 commit 8b53d09

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

parsers/base64/70-base64.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ module.exports = function(RED) {
1414
}
1515
else if (typeof msg.payload === "string") {
1616
// Take base64 string and make into binary buffer
17-
var regexp = new RegExp('^[A-Za-z0-9+\/=]*$');
18-
if ( regexp.test(msg.payload) && (msg.payload.length % 4 === 0) ) {
19-
msg.payload = new Buffer(msg.payload,'base64');
17+
var load = msg.payload.replace(/\s+/g,''); // remove any whitespace
18+
var regexp = new RegExp('^[A-Za-z0-9+\/=]*$'); // check it only contains valid characters
19+
if ( regexp.test(load) && (load.length % 4 === 0) ) {
20+
msg.payload = new Buffer(load,'base64');
2021
node.send(msg);
2122
}
2223
else {

parsers/base64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name" : "node-red-node-base64",
3-
"version" : "0.0.6",
3+
"version" : "0.0.7",
44
"description" : "A Node-RED node to pack and unpack objects to base64 format",
55
"dependencies" : {
66
},

0 commit comments

Comments
 (0)