deephaven / web-client-ui

Deephaven Web Client UI
Apache License 2.0
28 stars 30 forks source link

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

Closed bmingles closed 1 month ago

bmingles commented 1 month ago

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' }