Browse Source

Return null values when dealing with empty strings in dynamictyping mode

pull/471/head
Michele Fiordispina 7 years ago committed by Sergi Almacellas Abellana
parent
commit
3dbe4c92d1
  1. 2
      papaparse.js
  2. 9
      tests/test-cases.js

2
papaparse.js

@ -1123,7 +1123,7 @@ @@ -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)

9
tests/test-cases.js

@ -852,6 +852,15 @@ var PARSE_TESTS = [ @@ -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',

Loading…
Cancel
Save