From 0ad57c8c68a7e919a487c9d10dc6b46f9304977d Mon Sep 17 00:00:00 2001 From: dixso Date: Wed, 25 Nov 2015 17:05:25 +0100 Subject: [PATCH] Fix a problem with copying a cell containing a JSON. --- sheetclip.js | 3 +++ test/spec/09_json_single_column.json | 8 ++++++++ test/spec/09_json_single_column.txt | 6 ++++++ test/spec/ParseSpec.js | 16 ++++++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 test/spec/09_json_single_column.json create mode 100644 test/spec/09_json_single_column.txt diff --git a/sheetclip.js b/sheetclip.js index 58d6bc7..b5d1153 100644 --- a/sheetclip.js +++ b/sheetclip.js @@ -44,6 +44,9 @@ multiline = true; } else { + if (/\s?\:\s?(\"\")\s?/g.test(rows[r][c])) { + rows[r][c] = rows[r][c].replace(/(\s?\:\s?)(\"\")\s?/g, '$1"""'); + } arr[a].push(rows[r][c].replace(/""/g, '"')); multiline = false; } diff --git a/test/spec/09_json_single_column.json b/test/spec/09_json_single_column.json new file mode 100644 index 0000000..2eb7cd4 --- /dev/null +++ b/test/spec/09_json_single_column.json @@ -0,0 +1,8 @@ +[ + ["{\"A0\": \"A1\"}"], + ["{\"A0\": \"\"}"], + ["{\"A0\":\"\"}"], + ["{\"A0\": \"\"}"], + ["{\"A0\" : \"\"}"], + ["{\"A0\": \"\"}, {\"A1\": \"\"}"] +] \ No newline at end of file diff --git a/test/spec/09_json_single_column.txt b/test/spec/09_json_single_column.txt new file mode 100644 index 0000000..05771c7 --- /dev/null +++ b/test/spec/09_json_single_column.txt @@ -0,0 +1,6 @@ +{"A0": "A1"} +{"A0": ""} +{"A0":""} +{"A0": ""} +{"A0" : ""} +{"A0": ""}, {"A1": ""} \ No newline at end of file diff --git a/test/spec/ParseSpec.js b/test/spec/ParseSpec.js index a3e2d1d..862cc95 100644 --- a/test/spec/ParseSpec.js +++ b/test/spec/ParseSpec.js @@ -157,5 +157,21 @@ describe('SheetClip.parse', function () { }); }); + it('should parse a single column, where one of the cells is a JSON (09_json_single_column - output from Excel for Mac 2011)', function () { + var test = { + tsv: 'spec/09_json_single_column.txt', + json: 'spec/09_json_single_column.json' + }; + var files = {}; + + waitsFor(filesLoaded(test, files)); + + runs(function () { + var parsedTsv = SheetClip.parse(files.tsv); + var parsedJson = JSON.parse(files.json); + expect(parsedTsv).toEqual(parsedJson); + }); + }); + }); }); \ No newline at end of file