diff --git a/packages/node_modules/@node-red/nodes/core/storage/50-file.js b/packages/node_modules/@node-red/nodes/core/storage/50-file.js index 76cedb136..d55782785 100644 --- a/packages/node_modules/@node-red/nodes/core/storage/50-file.js +++ b/packages/node_modules/@node-red/nodes/core/storage/50-file.js @@ -169,7 +169,7 @@ module.exports = function(RED) { var node = this; this.on("input",function(msg) { - var filename = node.filename || msg.filename || ""; + var filename = (node.filename || msg.filename || "").replace(/\t|\r|\n/g,''); if (!node.filename) { node.status({fill:"grey",shape:"dot",text:filename}); } diff --git a/test/nodes/core/storage/50-file_spec.js b/test/nodes/core/storage/50-file_spec.js index da1d97468..901592ecc 100644 --- a/test/nodes/core/storage/50-file_spec.js +++ b/test/nodes/core/storage/50-file_spec.js @@ -140,7 +140,7 @@ describe('file Nodes', function() { var n2 = helper.getNode("helperNode1"); var data = ["one", "two", "three", "four"]; var count = 0; - + n2.on("input", function (msg) { try { msg.should.have.property("payload"); @@ -174,7 +174,7 @@ describe('file Nodes', function() { done(e); } }); - + // Send two messages to the file n1.receive({payload:"one"}); n1.receive({payload:"two"}); @@ -193,7 +193,7 @@ describe('file Nodes', function() { var n2 = helper.getNode("helperNode1"); var data = ["one", "two", "three", "four"]; var count = 0; - + n2.on("input", function (msg) { try { msg.should.have.property("payload"); @@ -254,7 +254,7 @@ describe('file Nodes', function() { helper.load(fileNode, flow, function() { var n1 = helper.getNode("fileNode1"); var n2 = helper.getNode("helperNode1"); - + n2.on("input", function (msg) { try { msg.should.have.property("payload", "fine"); @@ -286,7 +286,7 @@ describe('file Nodes', function() { helper.load(fileNode, flow, function() { var n1 = helper.getNode("fileNode1"); var n2 = helper.getNode("helperNode1"); - + n2.on("input", function (msg) { try { var f = fs.readFileSync(fileToTest).toString(); @@ -547,6 +547,7 @@ describe('file Nodes', function() { var resourcesDir = path.join(__dirname,"..","..","..","resources"); var fileToTest = path.join(resourcesDir,"50-file-test-file.txt"); + var fileToTest2 = "\t"+path.join(resourcesDir,"50-file-test-file.txt")+"\r\n"; var wait = 150; beforeEach(function(done) { @@ -608,6 +609,27 @@ describe('file Nodes', function() { }); }); + it('should read in a file ending in cr and output a utf8 string', function(done) { + var flow = [{id:"fileInNode1", type:"file in", name: "fileInNode", "filename":fileToTest2, "format":"utf8", wires:[["n2"]]}, + {id:"n2", type:"helper"}]; + helper.load(fileNode, flow, function() { + var n1 = helper.getNode("fileInNode1"); + var n2 = helper.getNode("n2"); + n2.on("input", function(msg) { + try { + msg.should.have.property('payload'); + msg.payload.should.be.a.String(); + msg.payload.should.have.length(40) + msg.payload.should.equal("File message line 1\nFile message line 2\n"); + done(); + } catch(err) { + done(err); + } + }); + n1.receive({payload:""}); + }); + }); + it('should read in a file and output split lines with parts', function(done) { var flow = [{id:"fileInNode1", type:"file in", name: "fileInNode", filename:fileToTest, format:"lines", wires:[["n2"]]}, {id:"n2", type:"helper"}];