From 3dbe4c92d13d8bf3a5290d521d8376e3e96ac03d Mon Sep 17 00:00:00 2001 From: Michele Fiordispina Date: Tue, 13 Mar 2018 10:08:27 +0000 Subject: [PATCH] Return null values when dealing with empty strings in dynamictyping mode --- papaparse.js | 2 +- tests/test-cases.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/papaparse.js b/papaparse.js index 048bd46..6c2a415 100755 --- a/papaparse.js +++ b/papaparse.js @@ -1123,7 +1123,7 @@ function tryParseFloat(val) { var isNumber = FLOAT.test(val); - return isNumber ? parseFloat(val) : val; + return isNumber ? parseFloat(val) : (val === '' ? null : val); } function addError(type, code, msg, row) diff --git a/tests/test-cases.js b/tests/test-cases.js index ea7fdcc..9ad3e9a 100644 --- a/tests/test-cases.js +++ b/tests/test-cases.js @@ -852,6 +852,15 @@ var PARSE_TESTS = [ errors: [] } }, + { + description: "Dynamic typing converts empty values into NULL", + input: '1,2.2,1e3\r\n,NULL,\r\n-,5a,null', + config: { dynamicTyping: true }, + expected: { + data: [[1, 2.2, 1000], [null, "NULL", null], ["-", "5a", "null"]], + errors: [] + } + }, { description: "Blank line at beginning", input: '\r\na,b,c\r\nd,e,f',