Skip to content

-printf: warn on unrecognized directives/escapes instead of dropping or erroring - #818

Open
MsfPablo wants to merge 1 commit into
uutils:mainfrom
MsfPablo:printf-unrecognized-directive-warn
Open

-printf: warn on unrecognized directives/escapes instead of dropping or erroring#818
MsfPablo wants to merge 1 commit into
uutils:mainfrom
MsfPablo:printf-unrecognized-directive-warn

Conversation

@MsfPablo

@MsfPablo MsfPablo commented Aug 7, 2026

Copy link
Copy Markdown

Summary

GNU findutils treats an unrecognized -printf directive/escape as a
warning and prints it literally, exiting 0. This diverged in two ways:

%X — the % was silently dropped

$ # GNU findutils 4.10.0
$ find d -printf '%€|\n'
find: warning: unrecognized format directive '%€'
%€|

$ # uutils, before this PR
$ find d -printf '%€|\n'
€|

\X — uutils errored instead of warning

$ # before this PR: hard error, exit 1
$ # after: warning + literal output, exit 0

Both cases now print a find: warning: ... message to stderr and emit
the directive/escape literally (with its %/\ prefix), matching GNU.

Along the way, fixed advance_one(): it sliced the remaining format
string at a fixed 1-byte offset, which panics on multibyte characters
(e.g. , as in the issue's own repro) immediately after % or \.
Switched to char::len_utf8().

Test plan

  • Added integration tests for both the multibyte (%€, \€) and
    the plain-ASCII unrecognized-directive case
  • Updated the two existing unit tests (test_parse_escapes,
    test_parse_formatting) that asserted the old (incorrect) behavior
  • cargo test — full suite green (226 unit + 61 integration tests)
  • cargo fmt --check clean
  • Manually verified output matches the GNU findutils transcript in the issue

Fixes #815

…or erroring

Two divergences from GNU find:

- An unrecognized %X directive silently dropped the '%' and printed
  only the following character.
- An unrecognized \X escape was a hard parse error (exit 1) instead of
  a warning.

Both now print a "find: warning: ..." message to stderr and emit the
directive/escape literally (with its '%' or '\' prefix), matching GNU
find's behavior and exit code (0).

Also fixes advance_one(), which sliced the remaining format string at
a fixed 1-byte offset and panicked on multibyte characters (e.g. '€')
immediately after '%' or '\' — using char::len_utf8() instead.

Fixes uutils#815
@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.93%. Comparing base (1f19cdd) to head (bdea188).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #818   +/-   ##
=======================================
  Coverage   91.93%   91.93%           
=======================================
  Files          35       35           
  Lines        7251     7256    +5     
  Branches      378      378           
=======================================
+ Hits         6666     6671    +5     
  Misses        443      443           
  Partials      142      142           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Commit bdea188 has test result changes:

GNU findutils testsuite:

Test results comparison:
  Current:   TOTAL: 495 / PASSED: 418 / FAILED: 76 / SKIPPED: 1
  Reference: TOTAL: 495 / PASSED: 417 / FAILED: 77 / SKIPPED: 1

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + tests/find/printf_escapechars

bfs testsuite:

Test results comparison:
  Current:   TOTAL: 315 / PASSED: 267 / FAILED: 42 / SKIPPED: 6
  Reference: TOTAL: 312 / PASSED: 266 / FAILED: 40 / SKIPPED: 6

Changes from main branch:
  TOTAL: +3
  PASSED: +1
  FAILED: +2

New test failures (2):
  - gnu/files0_from_ok
  - gnu/okdir_path_empty

@codspeed-hq

codspeed-hq Bot commented Aug 7, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing MsfPablo:printf-unrecognized-directive-warn (bdea188) with main (1f19cdd)

Open in CodSpeed

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.

-printf: unrecognized %X / \X directives should warn and print literally, not be dropped or error

1 participant