Skip to content

Commit 7249f25

Browse files
committed
add travis
1 parent bc4a389 commit 7249f25

6 files changed

Lines changed: 31 additions & 25 deletions

File tree

.travis.yml

Whitespace-only changes.

libs/core/utils.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,20 @@ function getDelimiter(rowStr,param) {
2727
});
2828
return rtn;
2929
}
30-
30+
function isQuoteOpen(str,param){
31+
var quote=param.quote;
32+
return str[0] === quote && (str[1]!==quote || str[1]===quote && (str[2] === quote || str.length ===2));
33+
}
34+
function isQuoteClose(str,param){
35+
var quote=param.quote;
36+
var count=0;
37+
var idx=str.length-1;
38+
while (str[idx] === quote){
39+
idx--;
40+
count++;
41+
}
42+
return count%2!==0;
43+
}
3144
function rowSplit(rowStr, param) {
3245
var quote=param.quote;
3346
var trim=param.trim;
@@ -47,34 +60,24 @@ function rowSplit(rowStr, param) {
4760
}
4861
var len=e.length;
4962
if (!inquote){
50-
if (e[0] === quote){ //possible open
63+
if (isQuoteOpen(e,param)){ //quote open
5164
e=e.substr(1);
52-
len-=1;
53-
if (e[0]!==quote){ // open quote
54-
if (e[len-1] === quote){ // possible close
55-
if (e[len-2]!==quote || e[len-2]===quote && e[len-3] === quote){ // close quote
56-
e=e.substring(0,len-1);
57-
e=twoDoubleQuote(e,quote);
58-
row.push(e);
59-
continue;
60-
}
61-
}
62-
inquote=true;
63-
quoteBuff+=e;
65+
if (isQuoteClose(e,param)){ //quote close
66+
e=e.substring(0,e.length-1);
67+
e=twoDoubleQuote(e,quote);
68+
row.push(e);
6469
continue;
6570
}else{
66-
if (len ===1){ // original column is empty quote pairs like ""
67-
e="";
68-
}
69-
row.push(e);
71+
inquote=true;
72+
quoteBuff+=e;
7073
continue;
7174
}
7275
}else{
73-
row.push(e);
74-
continue;
76+
row.push(e);
77+
continue;
7578
}
7679
}else{ //previous quote not closed
77-
if (e[len-1] === quote && (e[len-2] !==quote || e[len-2] === quote && e[len-3] === quote)){ //close double quote
80+
if (isQuoteClose(e,param)){ //close double quote
7881
inquote=false;
7982
e=e.substr(0,len-1);
8083
quoteBuff+=delimiter+e;

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@
4848
"grunt-newer": "^1.1.0",
4949
"imgur": "^0.1.5",
5050
"load-grunt-tasks": "^3.4.0",
51-
"mocha": "^2.2.5"
51+
"mocha": "^2.4.5"
5252
},
5353
"dependencies": {
5454
"async": "^1.2.1"
55+
},
56+
"scripts":{
57+
"test":"mocha ./test -R spec"
5558
}
5659
}

test/data/twodoublequotes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
title,actors,data,uuid,fieldA,fieldB
2-
hello world,"[""Neil"", ""Bill"""", ""Carl"",""Richard"",""Linus""]",xyabcde,"fejal""eifa","bnej""""falkfe",eisjfes
2+
"""","[""Neil"", ""Bill"""", ""Carl"",""Richard"",""Linus""]",xyabcde,"fejal""eifa","bnej""""falkfe",eisjfes

test/testCSVConverter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ describe("CSV Converter", function () {
149149
var csvConverter = new Converter();
150150
csvConverter.on("end_parsed", function () {});
151151
csvConverter.fromString(data, function (err, jsonObj) {
152-
assert(jsonObj[0].data === "xyabcde", jsonObj);
152+
assert.equal(jsonObj[0].title , "\"");
153+
assert.equal(jsonObj[0].data , "xyabcde");
153154
assert(jsonObj[0].uuid === "fejal\"eifa", jsonObj);
154155
assert(jsonObj[0].fieldA === "bnej\"\"falkfe", jsonObj);
155156
done();

test/testCSVConverter2.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ describe("CSV Converter", function() {
158158
var rs = fs.createReadStream(testData);
159159
var conv=new Converter({trim:true});
160160
conv.on("end_parsed",function(res){
161-
console.log(res);
162161
assert.equal(res[0].Description,"ac, abs, moon");
163162
assert.equal(res[1].Model,"Venture \"Extended Edition\"");
164163
assert.equal(res[2].Model,"Venture \"Extended Edition, Very Large\"");

0 commit comments

Comments
 (0)