From 045f658ef99996a042a476d8b8de9d82fdb8d652 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Mon, 30 Jun 2014 23:23:01 +0100 Subject: [PATCH] More defensive handling of missing filename in file node. (in line with jshint) --- nodes/core/storage/50-file.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/nodes/core/storage/50-file.js b/nodes/core/storage/50-file.js index 19ffb01f8..d6eb13357 100644 --- a/nodes/core/storage/50-file.js +++ b/nodes/core/storage/50-file.js @@ -20,23 +20,19 @@ module.exports = function(RED) { function FileNode(n) { RED.nodes.createNode(this,n); - - this.filename = n.filename; + this.filename = n.filename || ""; this.appendNewline = n.appendNewline; this.overwriteFile = n.overwriteFile; var node = this; this.on("input",function(msg) { var filename = msg.filename || this.filename; - if (filename === "") { node.warn('No filename specified'); } else if (typeof msg.payload != "undefined") { var data = msg.payload; if (typeof data == "object") { data = JSON.stringify(data); } if (typeof data == "boolean") { data = data.toString(); } - if (this.appendNewline) { - data += "\n"; - } + if (this.appendNewline) { data += "\n"; } if (msg.hasOwnProperty('delete')) { fs.unlink(filename, function (err) { if (err) { node.warn('Failed to delete file : '+err); } @@ -65,7 +61,7 @@ module.exports = function(RED) { function FileInNode(n) { RED.nodes.createNode(this,n); - this.filename = n.filename; + this.filename = n.filename || ""; this.format = n.format; var node = this; var options = {}; @@ -74,7 +70,6 @@ module.exports = function(RED) { } this.on("input",function(msg) { var filename = msg.filename || this.filename; - if (filename === "") { node.warn('No filename specified'); } else {