Skip to content

Commit 0a01470

Browse files
raynersknownasilya
authored andcommitted
fix: Ensure defaultValue is always applied in the case of nulls (#427)
1 parent d891c64 commit 0a01470

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed

lib/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
function getProp(obj, path, defaultValue) {
4-
return obj[path] === undefined ? defaultValue : obj[path];
4+
return (obj[path] === undefined || obj[path] === null) ? defaultValue : obj[path];
55
}
66

77
function setProp(obj, path, value) {

test/CLI.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ module.exports = (testRunner, jsonFixtures, csvFixtures) => {
360360
// Default value
361361

362362
testRunner.add('should output the default value as set in \'defaultValue\'', (t) => {
363-
const opts = ' --fields carModel,price --default-value ""';
363+
const opts = ' --fields carModel,price --default-value "-"';
364364

365365
child_process.exec(cli + '-i ' + getFixturePath('/json/defaultValueEmpty.json') + opts, (err, stdout, stderr) => {
366366
t.notOk(stderr);
@@ -372,7 +372,7 @@ module.exports = (testRunner, jsonFixtures, csvFixtures) => {
372372

373373
testRunner.add('should override \'options.defaultValue\' with \'field.defaultValue\'', (t) => {
374374
const opts = ' --fields-config ' + getFixturePath('/fields/overriddenDefaultValue.json')
375-
+ ' --default-value ""';
375+
+ ' --default-value "-"';
376376

377377
child_process.exec(cli + '-i ' + getFixturePath('/json/overriddenDefaultValue.json') + opts, (err, stdout, stderr) => {
378378
t.notOk(stderr);
@@ -384,7 +384,7 @@ module.exports = (testRunner, jsonFixtures, csvFixtures) => {
384384

385385
testRunner.add('should use \'options.defaultValue\' when no \'field.defaultValue\'', (t) => {
386386
const opts = ' --fields-config ' + getFixturePath('/fields/overriddenDefaultValue2.js')
387-
+ ' --default-value ""';
387+
+ ' --default-value "-"';
388388

389389
child_process.exec(cli + '-i ' + getFixturePath('/json/overriddenDefaultValue.json') + opts, (err, stdout, stderr) => {
390390
t.notOk(stderr);

test/JSON2CSVAsyncParser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ module.exports = (testRunner, jsonFixtures, csvFixtures, inMemoryJsonFixtures) =
513513
testRunner.add('should output the default value as set in \'defaultValue\'', (t) => {
514514
const opts = {
515515
fields: ['carModel', 'price'],
516-
defaultValue: ''
516+
defaultValue: '-'
517517
};
518518

519519
const parser = new AsyncParser(opts);
@@ -530,7 +530,7 @@ module.exports = (testRunner, jsonFixtures, csvFixtures, inMemoryJsonFixtures) =
530530
{ value: 'price', default: 1 },
531531
{ value: 'color' }
532532
],
533-
defaultValue: ''
533+
defaultValue: '-'
534534
};
535535

536536
const parser = new AsyncParser(opts);
@@ -556,7 +556,7 @@ module.exports = (testRunner, jsonFixtures, csvFixtures, inMemoryJsonFixtures) =
556556
value: row => row.color
557557
}
558558
],
559-
defaultValue: ''
559+
defaultValue: '-'
560560
};
561561

562562
const parser = new AsyncParser(opts);

test/JSON2CSVParser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ module.exports = (testRunner, jsonFixtures, csvFixtures) => {
413413
testRunner.add('should output the default value as set in \'defaultValue\'', (t) => {
414414
const opts = {
415415
fields: ['carModel', 'price'],
416-
defaultValue: ''
416+
defaultValue: '-'
417417
};
418418

419419
const parser = new Json2csvParser(opts);
@@ -430,7 +430,7 @@ module.exports = (testRunner, jsonFixtures, csvFixtures) => {
430430
{ value: 'price', default: 1 },
431431
{ value: 'color' }
432432
],
433-
defaultValue: ''
433+
defaultValue: '-'
434434
};
435435

436436
const parser = new Json2csvParser(opts);
@@ -456,7 +456,7 @@ module.exports = (testRunner, jsonFixtures, csvFixtures) => {
456456
value: row => row.color
457457
}
458458
],
459-
defaultValue: ''
459+
defaultValue: '-'
460460
};
461461

462462
const parser = new Json2csvParser(opts);

test/JSON2CSVTransform.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ module.exports = (testRunner, jsonFixtures, csvFixtures, inMemoryJsonFixtures) =
671671
testRunner.add('should output the default value as set in \'defaultValue\'', (t) => {
672672
const opts = {
673673
fields: ['carModel', 'price'],
674-
defaultValue: ''
674+
defaultValue: '-'
675675
};
676676

677677
const transform = new Json2csvTransform(opts);
@@ -697,7 +697,7 @@ module.exports = (testRunner, jsonFixtures, csvFixtures, inMemoryJsonFixtures) =
697697
{ value: 'price', default: 1 },
698698
{ value: 'color' }
699699
],
700-
defaultValue: ''
700+
defaultValue: '-'
701701
};
702702

703703
const transform = new Json2csvTransform(opts);
@@ -732,7 +732,7 @@ module.exports = (testRunner, jsonFixtures, csvFixtures, inMemoryJsonFixtures) =
732732
value: row => row.color
733733
}
734734
],
735-
defaultValue: ''
735+
defaultValue: '-'
736736
};
737737

738738
const transform = new Json2csvTransform(opts);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"carModel","price"
22
"Audi",0
33
"BMW",15000
4-
"Mercedes",
4+
"Mercedes","-"
55
"Porsche",30000
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"carModel","price","color"
22
"Audi",0,"blue"
33
"BMW",1,"red"
4-
"Mercedes",20000,""
4+
"Mercedes",20000,"-"
55
"Porsche",30000,"green"

0 commit comments

Comments
 (0)