Skip to content

Commit 1e6c32f

Browse files
committed
Fix #265
1 parent 6e6f0e7 commit 1e6c32f

7 files changed

Lines changed: 58 additions & 18 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ graph.png
1616
.vscode
1717
coverage/
1818
.nyc_output
19-
.coveralls.yml
19+
.coveralls.yml
20+
.ts-node

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@
294294
"scripts": {
295295
"dev": "tsc -w",
296296
"build": "rm -Rf ./v2 && tsc",
297-
"test": "TS_NODE_CACHE=false mocha -r ts-node/register src/**/*.test.ts ./test/*.ts -R spec",
297+
"test": "rm -Rf .ts-node && TS_NODE_CACHE_DIRECTORY=.ts-node mocha -r ts-node/register src/**/*.test.ts ./test/*.ts -R spec",
298298
"travis": "nyc --reporter lcov mocha -r ts-node/register src/**/*.test.ts ./test/*.ts -R spec",
299299
"test:debug": "mocha debug -r ts-node/register src/**/*.test.ts ./test/*.ts -R spec",
300300
"test-all": "mocha ./test -R spec && CSV_WORKER=3 mocha ./test -R spec ",

src/rowSplit.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,25 @@ describe("RowSplit.parse function", function () {
106106
assert.equal(res.closed, true);
107107
assert.equal(res.cells[2], 'csvtojson,a"\nwesome');
108108
});
109+
it ("should allow blank quotes",()=>{
110+
const data="a|^^|^b^";
111+
112+
const rowSplit = new RowSplit(new Converter({
113+
delimiter: '|',
114+
quote: '^',
115+
noheader: true
116+
}));
117+
const res=rowSplit.parse(data);
118+
assert.equal(res.cells[1],"");
119+
})
120+
it ("should allow blank quotes in quotes",()=>{
121+
const data='a,"hello,this,"", test"';
122+
123+
const rowSplit = new RowSplit(new Converter({
124+
noheader: true
125+
}));
126+
const res=rowSplit.parse(data);
127+
assert.equal(res.cells[1],'hello,this,", test');
128+
})
109129

110130
});

src/rowSplit.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ export class RowSplit {
6363
}
6464
const len = e.length;
6565
if (!inquote) {
66-
if (this.isQuoteOpen(e)) { //quote open
66+
if (len === 2 && e ===this.quote+this.quote){
67+
row.push("");
68+
continue;
69+
}else if (this.isQuoteOpen(e)) { //quote open
6770
e = e.substr(1);
6871
if (this.isQuoteClose(e)) { //quote close
6972
e = e.substring(0, e.lastIndexOf(quote));

test/testCSVConverter3.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ describe("testCSVConverter3", function () {
4646
.subscribe(function (json) {
4747
assert.equal(typeof json.column1, "string");
4848
assert.equal(json.column5, "hello world");
49-
assert.strictEqual(json["name#!"],false);
50-
assert.strictEqual(json["column9"],true);
49+
assert.strictEqual(json["name#!"], false);
50+
assert.strictEqual(json["column9"], true);
5151
})
5252
.on('done', function () {
5353
done()
@@ -194,26 +194,38 @@ describe("testCSVConverter3", function () {
194194
"1","2","3"
195195
"fefe,5",6`)
196196
.then((d) => {
197-
assert.equal(d[0].a,'"1"');
198-
assert.equal(d[0].b,'"2"');
199-
assert.equal(d[1].a,'"fefe');
200-
assert.equal(d[1].b,'5"');
197+
assert.equal(d[0].a, '"1"');
198+
assert.equal(d[0].b, '"2"');
199+
assert.equal(d[1].a, '"fefe');
200+
assert.equal(d[1].b, '5"');
201201
})
202202
})
203-
it ("should allow ignoreEmpty with checkColumn",()=>{
203+
it("should allow ignoreEmpty with checkColumn", () => {
204204
return csv({
205-
checkColumn:true,
205+
checkColumn: true,
206206
ignoreEmpty: true
207207
})
208-
.fromString(`date,altitude,airtime
208+
.fromString(`date,altitude,airtime
209209
2016-07-08,2000,23
210210
211211
2016-07-09,3000,43`)
212-
.then((data)=>{
212+
.then((data) => {
213213

214-
},(err)=>{
215-
console.log(err);
216-
assert(!err);
214+
}, (err) => {
215+
console.log(err);
216+
assert(!err);
217+
})
218+
});
219+
it("should allow quotes without content", () => {
220+
const data = "a|^^|^b^";
221+
return csv({
222+
delimiter: '|',
223+
quote: '^',
224+
noheader: true,
217225
})
226+
.fromString(data)
227+
.then((jsonObj) => {
228+
assert.equal(jsonObj[0].field2, "");
229+
});
218230
})
219231
});

v2/rowSplit.js

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

v2/rowSplit.js.map

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

0 commit comments

Comments
 (0)