Skip to content

date: escape control characters in invalid date messages like GNU - #14868

Merged
sylvestre merged 1 commit into
uutils:mainfrom
anasbekheit:date-escape-invalid-date
Oct 17, 2026
Merged

sylvestre merged 1 commit into
uutils:mainfrom
anasbekheit:date-escape-invalid-date

Conversation

@anasbekheit

Copy link
Copy Markdown
Contributor

The "invalid date" message printed the input as-is, so tabs, CR, backspace
and ESC in a -d argument or a -f line went to the terminal raw, and a file
could inject escape sequences. GNU escapes them.

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/date/resolution (passes in this run but fails in the 'main' branch)

Comment thread src/uu/date/src/date.rs
Comment thread src/uu/date/src/date.rs
Comment thread src/uu/date/src/date.rs Outdated
Ok(ParsedDateTime::Extended(_)) | Err(_) => {
return Err(Box::new(DateError::InvalidDate {
date: input.clone(),
date: escape_for_error(input.as_bytes()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a test in tests/by-util/test_date.rs for tab/CR/ESC with -d and with a -f file

Comment thread src/uu/date/src/date.rs Outdated
Ok(ParsedDateTime::Extended(date)) if allow_extended => Ok(ParsedDateTime::Extended(date)),
Ok(ParsedDateTime::Extended(_)) => Err((
input_str.into(),
escape_for_error(input_str.as_bytes()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the non-UTF-8 locale branch (quote + non-ASCII octal) isn't tested either, could you add one with LC_ALL=C?

@anasbekheit
anasbekheit force-pushed the date-escape-invalid-date branch 2 times, most recently from ae421c7 to 8d964ca Compare September 28, 2026 02:34
@codspeed

codspeed Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by ×2.3

⚠️ 117 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

ℹ️ 1 benchmark has no flame graph

The flamegraph could not be generated because too much time was spent in runtime internals, making the visualization not useful for performance analysis.

⚡ 1 improved benchmark
✅ 400 untouched benchmarks
⏩ 70 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Simulation factor_three_39_bit_primes 800.7 ms 345.6 ms ×2.3

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing anasbekheit:date-escape-invalid-date (1f969e4) with main (2fb77e8)

Open in CodSpeed

Footnotes

  1. 70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@anasbekheit

Copy link
Copy Markdown
Contributor Author

Are there any concerns blocking the merge of this PR?
@sylvestre @xtqqczze

Comment thread src/uucore/src/lib/features/quoting_style/mod.rs
@sylvestre

Copy link
Copy Markdown
Contributor

Sorry it needs to be rebased

@anasbekheit
anasbekheit force-pushed the date-escape-invalid-date branch from 8d964ca to d45055e Compare October 11, 2026 09:30
@anasbekheit

Copy link
Copy Markdown
Contributor Author

@sylvestre the branch is rebased.

@anasbekheit
anasbekheit force-pushed the date-escape-invalid-date branch from d45055e to 1f969e4 Compare October 15, 2026 10:59
@anasbekheit

Copy link
Copy Markdown
Contributor Author

@sylvestre, the branch is rebased again, are there any outstanding comments?

@xtqqczze
xtqqczze requested a review from sylvestre October 16, 2026 02:04
@sylvestre
sylvestre merged commit 8123c25 into uutils:main Oct 17, 2026
193 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants