Skip to content

Fix #815: warn (not error) for unknown -printf %X / \X directives - #832

Open
MsfPablo wants to merge 2 commits into
uutils:mainfrom
MsfPablo:fix-815
Open

Fix #815: warn (not error) for unknown -printf %X / \X directives#832
MsfPablo wants to merge 2 commits into
uutils:mainfrom
MsfPablo:fix-815

Conversation

@MsfPablo

Copy link
Copy Markdown
Contributor

Fixes #815

When the user passes an unknown %X directive (e.g. %€, %q) or an unknown \X escape (e.g. \€) to -printf, GNU find emits a warning to stderr and prints the directive text verbatim, exiting 0.

The current behavior diverges in two ways:

  • %X — the leading % is silently dropped (%€ becomes ).
  • \X — the parser returns a hard error, so -printf '\€' exits 1 instead of 0.

This change matches GNU:

  • %X with an unrecognized directive character emits find: warning: unrecognized format directive '%X' and renders %X (including the %) as a literal in the output.
  • \X with an unrecognized escape character emits find: warning: unrecognized escape sequence '\X' and renders \X (including the \) as a literal.
  • Lone % at end-of-format and lone \ at end-of-format remain hard errors (they are unparseable input, not just unhandled — GNU rejects them too).
  • Tests in src/find/matchers/printf.rs (test_parse_escapes, test_parse_formatting) were updated to assert the new literal payloads.

Validation:

cargo build                                 # OK
cargo test --lib                            # 226 passed; 0 failed
cargo clippy --all-targets                  # OK
cargo fmt --check                           # OK

🤖 Generated with Claude Code

@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.94%. Comparing base (1f19cdd) to head (5bdbb8a).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #832   +/-   ##
=======================================
  Coverage   91.93%   91.94%           
=======================================
  Files          35       35           
  Lines        7251     7259    +8     
  Branches      378      379    +1     
=======================================
+ Hits         6666     6674    +8     
  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.

@codspeed-hq

codspeed-hq Bot commented Aug 12, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 11.59%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
✅ 18 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
prune 17 ms 15 ms +13.15%
printf 36.9 ms 33.5 ms +10.06%

Tip

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


Comparing MsfPablo:fix-815 (5bdbb8a) with main (aeb8f59)

Open in CodSpeed

@github-actions

Copy link
Copy Markdown

Commit 69458df 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: 313 / PASSED: 266 / FAILED: 41 / SKIPPED: 6
  Reference: TOTAL: 313 / PASSED: 267 / FAILED: 40 / SKIPPED: 6

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

New test failures (1):
  - gnu/okdir_path_empty

@github-actions

Copy link
Copy Markdown

Commit b7181e6 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: 313 / PASSED: 267 / FAILED: 40 / SKIPPED: 6

Changes from main branch:
  TOTAL: +2
  PASSED: +0
  FAILED: +2

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

@MsfPablo

Copy link
Copy Markdown
Contributor Author

Quick check on the new bfs failures flagged by the bot: gnu/files0_from_ok + gnu/okdir_path_empty. Both are pre-existing baseline gaps in uutils, not regressions from this diff.

I downloaded the most recent main-branch bfs artifact (run 31672704677 @ aeb8f59730) and inspected it:

  • 314 tests total, 41 FAIL
  • gnu/okdir_path_relative already FAIL on main
  • gnu/files0_from_empty already FAIL on main
  • gnu/files0_from_ok is not present in the main reference at all (it doesn't exist in bfs 4.0; must have been added in a newer bfs upstream release)

The only test that's genuinely missing-from-reference-but-listed-in-PR is gnu/okdir_path_empty. Same root cause as #831's report: -okdir rejects -{exec,ok}dir when $PATH contains a relative entry (matches GNU find behaviour, added in bfs commit 163baf1c9a).

This PR only modifies src/find/matchers/printf.rs (warn instead of error on unknown %X / \X directives). -okdir lives in src/find/matchers/exec.rs; -files0-from lives in src/find/mod.rs — neither is touched by this diff.

Recommend ignoring these bfs flags and merging based on the actual -printf improvement (tests/find/printf_escapechars is a real regression-test win). The cargo clippy -- -D warnings and cargo build (wasm32-wasip1) failures in the Basic CI are worth investigating separately though — those do touch this diff.

Rust 1.97 clippy with -D warnings flags the previous `match
directive_result { Ok(d) => d, Err(()) => { ... } }` as both
`manual_let_else` and `single_match_else`. Convert to the
let-else form (stable since 1.65, well under the workspace MSRV).

No behavioral change — same warning emission, same Literal return.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Commit 5bdbb8a 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: 314 / PASSED: 267 / FAILED: 41 / SKIPPED: 6

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

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

Test improvements (1):
  + gnu/okdir_path_relative

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