Skip to content

Commit

Permalink
fix: backslash logic (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjoDiaz authored and knownasilya committed Jan 21, 2018
1 parent 9c861ed commit 29e9445
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
3 changes: 0 additions & 3 deletions lib/json2csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,6 @@ function createColumnContent(params, str) {
//remove last delimeter by its length
line = line.substring(0, line.length - params.delimiter.length);

//Remove the final excess backslashes from the stringified value.
line = line.replace(/\\\\/g,'\\');

//If header exists, add it, otherwise, print only content
if (str !== '') {
str += params.eol + line;
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/csv/backslashAtEnd.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"a string"
"with a description"
"with a description and ""quotes and backslash\"
"with a description and ""quotes and backslash\"
"with a description and ""quotes and backslash\\"
2 changes: 1 addition & 1 deletion test/fixtures/csv/backslashAtEndInMiddleColumn.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"uuid","title","id"
"xxxx-yyyy","$25 something $50 \","someId"
"xxxx-yyyy","$25 something $50 \","someId"
"xxxx-yyyy","$25 something $50 \\","someId"
8 changes: 4 additions & 4 deletions test/fixtures/csv/trailingBackslash.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"carModel","price","color"
"Audi\",0,"blue"
"BMW\",15000,"red"
"Mercedes\",20000,"yellow"
"Porsche\",30000,"green"
"Audi\\",0,"blue"
"BMW\\",15000,"red"
"Mercedes\\",20000,"yellow"
"Porsche\\",30000,"green"

0 comments on commit 29e9445

Please sign in to comment.