On 04/01/2026 17:41, Sylvestre Ledru wrote:
Hello

-d accepts some invalid inputs. For example:

$ /usr/bin/date -d "("
Sun Jan  4 00:00:00 CET 2026

The patch in gnulib rejects it, the other add a test in coreutils

with the patch:
$ ./src/date -d '('
date: invalid date ‘(’

Note that  /usr/bin/date -d "[", ".", "^" already generate an error

(found with a differential fuzzer)

Well parenthesis are special in GNU date as (documented)
they can be used to introduce comments.

  $ date --debug -d '2003(comment)-02-01'
  date: parsed date part: (Y-M-D) 2003-02-01
  date: input timezone: system default
  date: warning: using midnight as starting time: 00:00:00

Also related is that the empty string is considered valid,
and interpreted as time 0 of the current day.

  $ date --debug -d ''  date: parsed number part: 00:00:00
  date: input timezone: system default
  date: using specified time as starting value: '00:00:00'

Also a single '(' is treated as comment to end of line

  $ date --debug -d '1(ignore comment to eol'
  date: parsed number part: 01:00:00
  date: input timezone: system default
  date: using specified time as starting value: '01:00:00'

So in combination the single '(' is treated like ''

I'm not sure we should change this.
Like some script may be defaulting to midnight like:

  $ date -d "$optional_time"

cheers,
Padraig

Reply via email to