From f700c4cb37e3fc723914deb722ab52abe0d162f9 Mon Sep 17 00:00:00 2001 From: Juanjo Diaz Date: Sun, 21 Jan 2018 11:23:21 +0200 Subject: [PATCH] Fix backslash logic --- lib/json2csv.js | 3 --- test/fixtures/csv/backslashAtEnd.csv | 2 +- test/fixtures/csv/backslashAtEndInMiddleColumn.csv | 2 +- test/fixtures/csv/trailingBackslash.csv | 8 ++++---- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/json2csv.js b/lib/json2csv.js index 3cf044cd..6154024b 100644 --- a/lib/json2csv.js +++ b/lib/json2csv.js @@ -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; diff --git a/test/fixtures/csv/backslashAtEnd.csv b/test/fixtures/csv/backslashAtEnd.csv index 65166a50..8035382a 100644 --- a/test/fixtures/csv/backslashAtEnd.csv +++ b/test/fixtures/csv/backslashAtEnd.csv @@ -1,4 +1,4 @@ "a string" "with a description" "with a description and ""quotes and backslash\" -"with a description and ""quotes and backslash\" \ No newline at end of file +"with a description and ""quotes and backslash\\" \ No newline at end of file diff --git a/test/fixtures/csv/backslashAtEndInMiddleColumn.csv b/test/fixtures/csv/backslashAtEndInMiddleColumn.csv index 26a778bb..1659b6d2 100644 --- a/test/fixtures/csv/backslashAtEndInMiddleColumn.csv +++ b/test/fixtures/csv/backslashAtEndInMiddleColumn.csv @@ -1,3 +1,3 @@ "uuid","title","id" "xxxx-yyyy","$25 something $50 \","someId" -"xxxx-yyyy","$25 something $50 \","someId" \ No newline at end of file +"xxxx-yyyy","$25 something $50 \\","someId" \ No newline at end of file diff --git a/test/fixtures/csv/trailingBackslash.csv b/test/fixtures/csv/trailingBackslash.csv index a85ce16f..60592010 100644 --- a/test/fixtures/csv/trailingBackslash.csv +++ b/test/fixtures/csv/trailingBackslash.csv @@ -1,5 +1,5 @@ "carModel","price","color" -"Audi\",0,"blue" -"BMW\",15000,"red" -"Mercedes\",20000,"yellow" -"Porsche\",30000,"green" \ No newline at end of file +"Audi\\",0,"blue" +"BMW\\",15000,"red" +"Mercedes\\",20000,"yellow" +"Porsche\\",30000,"green" \ No newline at end of file