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

Fix join node reset issue with merging objects

and add tests
to close #2188
This commit is contained in:
Dave Conway-Jones 2019-06-20 18:14:46 +01:00
parent 8486f4d43a
commit f3fc083330
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
2 changed files with 9 additions and 2 deletions

View File

@ -572,6 +572,8 @@ module.exports = function(RED) {
}
}
if (msg.hasOwnProperty("reset")) { if (inflight[partId]) { delete inflight[partId] }; return; }
if ((payloadType === 'object') && (propertyKey === null || propertyKey === undefined || propertyKey === "")) {
if (node.mode === "auto") {
node.warn("Message missing 'msg.parts.key' property - cannot add to object");
@ -590,7 +592,6 @@ module.exports = function(RED) {
return;
}
if (msg.hasOwnProperty("reset")) { if (inflight[partid]) { delete inflight[partId] } return; }
if (!inflight.hasOwnProperty(partId)) {
if (payloadType === 'object' || payloadType === 'merged') {
inflight[partId] = {
@ -631,7 +632,7 @@ module.exports = function(RED) {
}
if (payloadType === 'object') {
group.payload[propertyKey] = property;
group.currentCount = (group.currentCount || 0) + 1;
group.currentCount = Object.keys(group.payload).length;
} else if (payloadType === 'merged') {
if (Array.isArray(property) || typeof property !== 'object') {
if (!msg.hasOwnProperty("complete")) {

View File

@ -677,6 +677,9 @@ describe('JOIN node', function() {
n1.receive({payload:{f:1}, topic:"f", complete:true});
n1.receive({payload:{g:2}, topic:"g"});
n1.receive({payload:{h:1}, topic:"h"});
n1.receive({reset:true});
n1.receive({payload:{g:2}, topic:"g"});
n1.receive({payload:{h:1}, topic:"h"});
n1.receive({payload:{i:3}, topic:"i"});
});
});
@ -700,6 +703,9 @@ describe('JOIN node', function() {
}
catch(e) { done(e) }
});
n1.receive({payload:2, foo:"b"});
n1.receive({payload:3, foo:"c"});
n1.receive({reset:true});
n1.receive({payload:1, foo:"a"});
n1.receive({payload:2, foo:"b"});
n1.receive({payload:3, foo:"c"});