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

Open
#279 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
65/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
rust
Domain
backend

Research direction

Start at the parse_datetime entry point and inspect how trailing word-tokens are handled, then review the proposed test in the uutils/coreutils integration suite. Run the date cases for "8j" and "8 j" in the reproduction; done means both inputs succeed and produce 08:00:00 while existing parsing tests continue to pass.

Written by the indexing model from the issue text.

Description

bug good first issue

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");
    }
}
Dominant language
Rust
Stars
37
Forks
39
Avg merge
17h 48m
Merged PRs (30d)
8

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from uutils/parse_datetime

All issues in uutils/parse_datetime

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.