From 113d561c4c69f66181a9f09ac17c39e9a8f879c3 Mon Sep 17 00:00:00 2001 From: Christopher Eady Date: Fri, 28 May 2021 01:39:04 -0500 Subject: [PATCH] Update ISO_DATE regex to match full string (#872) --- papaparse.js | 2 +- tests/test-cases.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/papaparse.js b/papaparse.js index 26db15c..83ee4d0 100755 --- a/papaparse.js +++ b/papaparse.js @@ -1008,7 +1008,7 @@ License: MIT var MAX_FLOAT = Math.pow(2, 53); var MIN_FLOAT = -MAX_FLOAT; 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 _stepCounter = 0; // Number of times step was called (number of rows parsed) var _rowCounter = 0; // Number of rows that have been parsed so far diff --git a/tests/test-cases.js b/tests/test-cases.js index 8d15b29..d727bfe 100644 --- a/tests/test-cases.js +++ b/tests/test-cases.js @@ -997,6 +997,15 @@ var PARSE_TESTS = [ 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", input: '\r\na,b,c\r\nd,e,f',