1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

remove cr lf from incoming filename so easier to pass in results from exec node.

and add test
This commit is contained in:
Dave Conway-Jones 2018-09-23 10:36:50 +01:00
parent 51f875c02d
commit fde157ff50
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
2 changed files with 28 additions and 6 deletions

View File

@ -169,7 +169,7 @@ module.exports = function(RED) {
var node = this; var node = this;
this.on("input",function(msg) { 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) { if (!node.filename) {
node.status({fill:"grey",shape:"dot",text:filename}); node.status({fill:"grey",shape:"dot",text:filename});
} }

View File

@ -140,7 +140,7 @@ describe('file Nodes', function() {
var n2 = helper.getNode("helperNode1"); var n2 = helper.getNode("helperNode1");
var data = ["one", "two", "three", "four"]; var data = ["one", "two", "three", "four"];
var count = 0; var count = 0;
n2.on("input", function (msg) { n2.on("input", function (msg) {
try { try {
msg.should.have.property("payload"); msg.should.have.property("payload");
@ -174,7 +174,7 @@ describe('file Nodes', function() {
done(e); done(e);
} }
}); });
// Send two messages to the file // Send two messages to the file
n1.receive({payload:"one"}); n1.receive({payload:"one"});
n1.receive({payload:"two"}); n1.receive({payload:"two"});
@ -193,7 +193,7 @@ describe('file Nodes', function() {
var n2 = helper.getNode("helperNode1"); var n2 = helper.getNode("helperNode1");
var data = ["one", "two", "three", "four"]; var data = ["one", "two", "three", "four"];
var count = 0; var count = 0;
n2.on("input", function (msg) { n2.on("input", function (msg) {
try { try {
msg.should.have.property("payload"); msg.should.have.property("payload");
@ -254,7 +254,7 @@ describe('file Nodes', function() {
helper.load(fileNode, flow, function() { helper.load(fileNode, flow, function() {
var n1 = helper.getNode("fileNode1"); var n1 = helper.getNode("fileNode1");
var n2 = helper.getNode("helperNode1"); var n2 = helper.getNode("helperNode1");
n2.on("input", function (msg) { n2.on("input", function (msg) {
try { try {
msg.should.have.property("payload", "fine"); msg.should.have.property("payload", "fine");
@ -286,7 +286,7 @@ describe('file Nodes', function() {
helper.load(fileNode, flow, function() { helper.load(fileNode, flow, function() {
var n1 = helper.getNode("fileNode1"); var n1 = helper.getNode("fileNode1");
var n2 = helper.getNode("helperNode1"); var n2 = helper.getNode("helperNode1");
n2.on("input", function (msg) { n2.on("input", function (msg) {
try { try {
var f = fs.readFileSync(fileToTest).toString(); var f = fs.readFileSync(fileToTest).toString();
@ -547,6 +547,7 @@ describe('file Nodes', function() {
var resourcesDir = path.join(__dirname,"..","..","..","resources"); var resourcesDir = path.join(__dirname,"..","..","..","resources");
var fileToTest = path.join(resourcesDir,"50-file-test-file.txt"); 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; var wait = 150;
beforeEach(function(done) { 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) { 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"]]}, var flow = [{id:"fileInNode1", type:"file in", name: "fileInNode", filename:fileToTest, format:"lines", wires:[["n2"]]},
{id:"n2", type:"helper"}]; {id:"n2", type:"helper"}];