Skip to content

DateUtils.parseDateTimeString - month token parsing is too permissive #2102

@bmingles

Description

@bmingles

We currently parse date time strings for IrisGrid goto row + conditional formatting features in our grids. The backing util is DateUtils.parseDateTimeString.

It uses a RegEx with capture groups to identify date / time tokens:
/\s*(\d{4})([-./]([\da-z]+))?([-./](\d{1,2}))?([tT\s](\d{2})([:](\d{2}))?([:](\d{2}))?([.](\d{1,9}))?)?(.*)/;

And then spreads the matches:

const [
  ,
  year,
  ,
  month, // ([\da-z]+)
  ,
  date,
  ,
  hours,
  ,
  minutes,
  ,
  seconds,
  ,
  nanos,
  overflow,
] = result;

The capture group for the month token is ([\da-z]+) which is presumably intended to match numeric months or some text form of month (maybe 'jan', 'feb', etc.?). This is not documented and the unit test coverage doesn't seem to include any test cases for the string values.

As-is:
2024-04overflow parses to { year: '2012', month: '04overflow' } whereas

2012-04-04overflow parses to { year: '2012', month: '04', date: '20', overflow: 'overflow' }

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions