mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fix handling in file nodes when number is specified as file name
This commit is contained in:
parent
4d3e3a73fd
commit
0dd771351d
@ -68,6 +68,9 @@ module.exports = function(RED) {
|
|||||||
node.error(err,msg);
|
node.error(err,msg);
|
||||||
return done();
|
return done();
|
||||||
} else {
|
} else {
|
||||||
|
if (value) {
|
||||||
|
value = value.toString();
|
||||||
|
}
|
||||||
processMsg2(msg,nodeSend,value,done);
|
processMsg2(msg,nodeSend,value,done);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -278,7 +281,6 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
RED.nodes.registerType("file",FileNode);
|
RED.nodes.registerType("file",FileNode);
|
||||||
|
|
||||||
|
|
||||||
function FileInNode(n) {
|
function FileInNode(n) {
|
||||||
// Read a file
|
// Read a file
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
@ -314,6 +316,9 @@ module.exports = function(RED) {
|
|||||||
node.error(err,msg);
|
node.error(err,msg);
|
||||||
return done();
|
return done();
|
||||||
} else {
|
} else {
|
||||||
|
if (value) {
|
||||||
|
value = value.toString();
|
||||||
|
}
|
||||||
processMsg2(msg, nodeSend, (value || "").replace(/\t|\r|\n/g,''), nodeDone);
|
processMsg2(msg, nodeSend, (value || "").replace(/\t|\r|\n/g,''), nodeDone);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -121,7 +121,6 @@ describe('file Nodes', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should write to a file using RED.settings.fileWorkingDirectory', function(done) {
|
it('should write to a file using RED.settings.fileWorkingDirectory', function(done) {
|
||||||
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":relativePathToFile, "appendNewline":false, "overwriteFile":true, wires: [["helperNode1"]]},
|
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":relativePathToFile, "appendNewline":false, "overwriteFile":true, wires: [["helperNode1"]]},
|
||||||
{id:"helperNode1", type:"helper"}];
|
{id:"helperNode1", type:"helper"}];
|
||||||
@ -145,7 +144,6 @@ describe('file Nodes', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should write multi-byte string to a file', function(done) {
|
it('should write multi-byte string to a file', function(done) {
|
||||||
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":false, "overwriteFile":true, wires: [["helperNode1"]]},
|
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":false, "overwriteFile":true, wires: [["helperNode1"]]},
|
||||||
{id:"helperNode1", type:"helper"}];
|
{id:"helperNode1", type:"helper"}];
|
||||||
@ -447,6 +445,31 @@ describe('file Nodes', function() {
|
|||||||
n1.receive({payload:"typedInput", _user_specified_filename:fileToTest});
|
n1.receive({payload:"typedInput", _user_specified_filename:fileToTest});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should support number in msg._user_specified_filename', function (done) {
|
||||||
|
var flow = [{id:"fileNode1", type:"file", filename:"_user_specified_filename", filenameType:"msg", name:"fileNode", "appendNewline":false, "overwriteFile":true, wires:[["helperNode1"]]},
|
||||||
|
{id:"helperNode1", type:"helper"}];
|
||||||
|
helper.load(fileNode, flow, function () {
|
||||||
|
RED.settings.fileWorkingDirectory = resourcesDir;
|
||||||
|
var n1 = helper.getNode("fileNode1");
|
||||||
|
var n2 = helper.getNode("helperNode1");
|
||||||
|
n2.on("input", function (msg) {
|
||||||
|
try {
|
||||||
|
var fileToTest = path.join(resourcesDir, "123");
|
||||||
|
var f = fs.readFileSync(fileToTest);
|
||||||
|
f.should.have.length(4);
|
||||||
|
fs.unlinkSync(fileToTest);
|
||||||
|
msg.should.have.property("payload", "test");
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
n1.receive({payload: "test", _user_specified_filename: 123});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should use env.TEST_FILE set in nodes typedInput', function(done) {
|
it('should use env.TEST_FILE set in nodes typedInput', function(done) {
|
||||||
var flow = [{id:"fileNode1", type:"file", filename:"TEST_FILE", filenameType: "env", name: "fileNode", "appendNewline":true, "overwriteFile":true, wires: [["helperNode1"]]},
|
var flow = [{id:"fileNode1", type:"file", filename:"TEST_FILE", filenameType: "env", name: "fileNode", "appendNewline":true, "overwriteFile":true, wires: [["helperNode1"]]},
|
||||||
{id:"helperNode1", type:"helper"}];
|
{id:"helperNode1", type:"helper"}];
|
||||||
|
Loading…
Reference in New Issue
Block a user