Skip to content

Commit

Permalink
fix(core): prevent setting random fields when using loadAll (#3277)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardobridge authored Aug 6, 2024
1 parent 4f6f322 commit e1fa2a7
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/core/lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,18 +407,27 @@ function datafileVariables(script) {
let result = {};
if (script.config.payload) {
_.each(script.config.payload, function (el) {
// If data = [] (i.e. the CSV file is empty, or only has headers and
// skipHeaders = true), then row could = undefined
let row = el.reader(el.data) || [];
_.each(el.fields, function (fieldName, j) {
result[fieldName] = row[j];
});
//when loading all the csv, we don't set individual fields
if (!el.loadAll) {
// If data = [] (i.e. the CSV file is empty, or only has headers and
// skipHeaders = true), then row could = undefined
let row = el.reader(el.data) || [];
_.each(el.fields, function (fieldName, j) {
result[fieldName] = row[j];
});
}

if (typeof el.name !== 'undefined') {
// Make the entire CSV available
result[el.name] = el.reader(el.data);
} else {
console.log(
'WARNING: loadAll is set to true but no name is provided for the CSV data'
);
}
});
}

return result;
}

Expand Down

0 comments on commit e1fa2a7

Please sign in to comment.