Skip to content

Commit 35e26d5

Browse files
committed
Fix d3#2010 - check for nully, not falsey.
1 parent f38ed05 commit 35e26d5

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

d3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,7 @@
19971997
a.push(t);
19981998
t = token();
19991999
}
2000-
if (f && !(a = f(a, n++))) continue;
2000+
if (f && (a = f(a, n++)) == null) continue;
20012001
rows.push(a);
20022002
}
20032003
return rows;

d3.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dsv/dsv.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ d3.dsv = function(delimiter, mimeType) {
9393
a.push(t);
9494
t = token();
9595
}
96-
if (f && !(a = f(a, n++))) continue;
96+
if (f && (a = f(a, n++)) == null) continue;
9797
rows.push(a);
9898
}
9999

test/dsv/csv-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ suite.addBatch({
106106
"skips rows if the row function returns null or undefined": function(csv) {
107107
assert.deepEqual(csv.parse("a,b,c\n1,2,3\n2,3,4", function(row) { return row.a & 1 ? null : row; }), [{a: "2", b: "3", c: "4"}]);
108108
assert.deepEqual(csv.parse("a,b,c\n1,2,3\n2,3,4", function(row) { return row.a & 1 ? undefined : row; }), [{a: "2", b: "3", c: "4"}]);
109+
},
110+
"does not skip rows if the row function returns false or 0": function(csv) {
111+
assert.deepEqual(csv.parse("a,b,c\n1,2,3\n2,3,4", function(row) { return row.a & 1 ? 0 : row; }), [0, {a: "2", b: "3", c: "4"}]);
112+
assert.deepEqual(csv.parse("a,b,c\n1,2,3\n2,3,4", function(row) { return row.a & 1 ? false : row; }), [false, {a: "2", b: "3", c: "4"}]);
109113
}
110114
},
111115

test/dsv/tsv-test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,30 @@ suite.addBatch({
7777
}
7878
},
7979

80+
"parse with row function": {
81+
"invokes the row function for every row in order": function(tsv) {
82+
var rows = [];
83+
tsv.parse("a\n1\n2\n3\n4", function(d, i) { rows.push({d: d, i: i}); });
84+
assert.deepEqual(rows, [
85+
{d: {a: "1"}, i: 0},
86+
{d: {a: "2"}, i: 1},
87+
{d: {a: "3"}, i: 2},
88+
{d: {a: "4"}, i: 3}
89+
]);
90+
},
91+
"returns an array of the row function return values": function(tsv) {
92+
assert.deepEqual(tsv.parse("a\tb\tc\n1\t2\t3\n", function(row) { return row; }), [{a: "1", b: "2", c: "3"}]);
93+
},
94+
"skips rows if the row function returns null or undefined": function(tsv) {
95+
assert.deepEqual(tsv.parse("a\tb\tc\n1\t2\t3\n2\t3\t4", function(row) { return row.a & 1 ? null : row; }), [{a: "2", b: "3", c: "4"}]);
96+
assert.deepEqual(tsv.parse("a\tb\tc\n1\t2\t3\n2\t3\t4", function(row) { return row.a & 1 ? undefined : row; }), [{a: "2", b: "3", c: "4"}]);
97+
},
98+
"does not skip rows if the row function returns false or 0": function(tsv) {
99+
assert.deepEqual(tsv.parse("a\tb\tc\n1\t2\t3\n2\t3\t4", function(row) { return row.a & 1 ? 0 : row; }), [0, {a: "2", b: "3", c: "4"}]);
100+
assert.deepEqual(tsv.parse("a\tb\tc\n1\t2\t3\n2\t3\t4", function(row) { return row.a & 1 ? false : row; }), [false, {a: "2", b: "3", c: "4"}]);
101+
}
102+
},
103+
80104
"parseRows": {
81105
topic: function(tsv) {
82106
return tsv.parseRows;

0 commit comments

Comments
 (0)