Repository navigation
fix: fast-path differential divergences #707/#708/#709 (tr carriers, head -n parsing, dirname/basename edges) - #718
Merged
Conversation
) GNU dirname keeps a leading // and returns . for an empty operand; basename returns the empty string for an empty operand. The inline fast paths collapsed all-slash and empty values to / via trim_trailing_slashes. Reimplement dirname with the GNU mdir_name/last_component/dir_len algorithm (preserving //-but-not-///) and special-case the empty basename operand; the all-slash basename spelling stays / to match the external WinuxCmd fallback.
…to 10 (#708) The inline head arms skipped every -option word and fell through head_line_count(...).unwrap_or(10), so an unparsable count printed the first ten lines with rc 0 and GNU's negative form (-n -1 = all but the last line) was lost. Add a strict parser shared by the pipeline and command-substitution arms: only -n N / -nN / --lines=N / --lines N / -N (non-negative) and the negative -n -N form stay inline; -c/--bytes, unknown options, operands and a missing operand decline to the real head, which reports the error.
The inline tr arms ran set membership over the shell's transport text. Carrier bytes (0x0C, 0x1B, 0x14..0x1F) travel as U+E000+U+E0xx marker pairs, so [:cntrl:]/[:space:] never matched them and the carried control bytes escaped translation. translate_tr now decodes to the exact payload bytes (shell_text_to_raw_bytes) before matching and re-encodes the result, so both the pipeline and command-substitution arms are fixed at the shared boundary.
This was referenced Oct 17, 2026
Closed
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes three confirmed fast-path divergences found by the differential audit in #706.
#707 —
trinline arm lets carried control bytes escape its classesThe inline
trarms ran set membership over the shell's transport text. Carrier bytes (0x0C,0x1B,0x14..0x1F) travel asU+E000+U+E0xxmarker pairs, so[:cntrl:]/[:space:]never matched them.translate_trnow decodes once (shell_text_to_raw_bytes) before matching and re-encodes the result, fixing both the pipeline arm and the command-substitution arm at their shared boundary.printf 'a\033b\nc\n' | tr '[:cntrl:]' Xa\x1bbXcXaXbXcXaXbXcXprintf 'a\014b\n' | tr '[:space:]' _a\x0cb_a_b_a_b_printf 'a\013\014b\n' | tr '[:cntrl:]' XaX\x0cbXaXXbXaXXbX#708 —
headinline arm silently defaults invalid/missing/negative-nThe arms skipped every
-…word and fell throughhead_line_count(...).unwrap_or(10), so a malformed count printed the first ten lines with rc 0 and GNU's negative form was lost. A strictparse_head_line_countshared by the pipeline and command-substitution arms now keeps only representable count forms inline; everything else declines to the realhead.head -n -1a\nb\na\nbhead -n abchead -xhead -nhead --linesx=$(… | head -n -1)a\nba\nb#709 —
dirname/basenamestring edgestrim_trailing_slashescollapsed both//and''to/.dirnamenow implements GNUmdir_name/last_component/dir_len(preserving a leading//but not///), andbasenamereturns the empty string for an empty operand. The all-slashbasenamespelling stays/because that is what the external WinuxCmd fallback reports (a shared divergence, explicitly out of scope in #709).dirname ///////dirname //a/////dirname ''/..basename ''/Harness delta (#706, run from
origin/audit/fast-path-differential, not modified)Run against a build of this branch (the
knownlist still carries the old expectations, so the harness reports each fixed case asFIXED?):tr_class_cntrl,tr_class_space,tr_cntrl_mixed— KNOWN → pass (FAST == EXT == GNU).head_negn1,head_badnum,head_unknown,head_missing_arg,head_long_missing,sub_head_negn1,sub_head_badnum— KNOWN → pass.dirname_doubleslash,dirname_lead_double_letter,dirname_empty,basename_empty— KNOWN → pass. (dirname_tripleslashstaysEXTBUG: the fast path already agrees with GNU and only the bundled WinuxCmddirname.exeis wrong;basename_doubleslashstays a shared FAST==EXT divergence — both left alone.)The four path-translation
dirnamerows (dirname_simple,dirname_letter,dirname_trailing,dirname_letter_double) already pass on currentorigin/master(#649); the committedknownannotations reflect a stale installed binary and are not caused by this change.Full harness: no new regressions. The single reported
grep_utf8_idivergence reproduces identically on pristineorigin/master(verified with a clean worktree build) and is unrelated to these files.Tests
Added
tests/issue707_tr_carrier_classes.rs,tests/issue708_head_option_parsing.rs,tests/issue709_dirname_basename_edges.rscovering every shape above plus a no-regression case for each command's ordinary path.Found but left alone
--internal-head(src/main.rsinternal_head_line_count) has the same default-10/negative-count shape. It is only reached when no externalheadexists onPATH, so the audit cannot exercise it, and inline head fast path silently defaults invalid/missing/negative -n to 10 lines (flag parsing) #708 scopes the fix to the two executor arms.basename //→/(matches WinuxCmd, diverges from GNU//) anddirname ///(WinuxCmd-onlyEXTBUG) are shared divergences called out as out of scope in dirname/basename fast path: leading // and empty operand mishandled (string edge cases) #709.