Skip to content

date input: unrecognized trailing tokens rejected (e.g. 8j, 8 j) #279

@sylvestre

Description

@sylvestre

Summary

GNU date silently ignores unrecognized trailing word-tokens and parses the preceding number as an hour. parse_datetime errors out instead.

Found by a fuzz_date run on uutils/coreutils.

Reproduction

$ TZ=UTC /usr/bin/date -u -d '8j' '+%H:%M:%S'
08:00:00
$ echo $?
0

$ TZ=UTC target/debug/coreutils date -u -d '8j' '+%H:%M:%S'
date: invalid date '8j'
$ echo $?
1

$ TZ=UTC /usr/bin/date -u -d '8 j' '+%H:%M:%S'
08:00:00

$ TZ=UTC target/debug/coreutils date -u -d '8 j' '+%H:%M:%S'
date: invalid date '8 j'

Test (in uutils/coreutils integration suite)

#[test]
fn test_date_ignores_unrecognized_trailing_tokens() {
    for input in ["8j", "8 j"] {
        new_ucmd!()
            .env("TZ", "UTC")
            .arg("-u")
            .arg("-d")
            .arg(input)
            .arg("+%H:%M:%S")
            .succeeds()
            .stdout_only("08:00:00\n");
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions