Browse Source

Update ISO_DATE regex to match full string (#872)

pull/876/head
Christopher Eady 4 years ago committed by GitHub
parent
commit
113d561c4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      papaparse.js
  2. 9
      tests/test-cases.js

2
papaparse.js

@ -1008,7 +1008,7 @@ License: MIT
var MAX_FLOAT = Math.pow(2, 53); var MAX_FLOAT = Math.pow(2, 53);
var MIN_FLOAT = -MAX_FLOAT; var MIN_FLOAT = -MAX_FLOAT;
var FLOAT = /^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/; var FLOAT = /^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/;
var ISO_DATE = /(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/; var ISO_DATE = /^(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))$/;
var self = this; var self = this;
var _stepCounter = 0; // Number of times step was called (number of rows parsed) var _stepCounter = 0; // Number of times step was called (number of rows parsed)
var _rowCounter = 0; // Number of rows that have been parsed so far var _rowCounter = 0; // Number of rows that have been parsed so far

9
tests/test-cases.js

@ -997,6 +997,15 @@ var PARSE_TESTS = [
errors: [] errors: []
} }
}, },
{
description: "Dynamic typing skips ISO date strings ocurring in other strings",
input: 'ISO date,String with ISO date\r\n2018-05-04T21:08:03.269Z,The date is 2018-05-04T21:08:03.269Z\r\n2018-05-08T15:20:22.642Z,The date is 2018-05-08T15:20:22.642Z',
config: { dynamicTyping: true },
expected: {
data: [["ISO date", "String with ISO date"], [new Date("2018-05-04T21:08:03.269Z"), "The date is 2018-05-04T21:08:03.269Z"], [new Date("2018-05-08T15:20:22.642Z"), "The date is 2018-05-08T15:20:22.642Z"]],
errors: []
}
},
{ {
description: "Blank line at beginning", description: "Blank line at beginning",
input: '\r\na,b,c\r\nd,e,f', input: '\r\na,b,c\r\nd,e,f',

Loading…
Cancel
Save