Visitar URL original
fix(shell): don't truncate config scan at a non-UTF-8 line by worktrunk-bot · Pull Request #3499 · max-sixty/worktrunk · GitHub
Skip to content

fix(shell): don't truncate config scan at a non-UTF-8 line - #3499

Merged
max-sixty merged 1 commit into
mainfrom
fix/shell-detection-nonutf8-truncation
Jul 17, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/shell-detection-nonutf8-truncation

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Problem

scan_file in src/shell/detection.rs iterated shell config files with reader.lines().map_while(Result::ok). map_while stops at the first Err, and BufRead::lines() yields Err(InvalidData) for any line that isn't valid UTF-8. So a single non-UTF-8 line — an accented comment saved as Latin-1, a stray binary paste — anywhere above the eval "$(wt config shell init …)" line caused the scan to stop before reaching it. Detection then reported shell integration as not installed for a config that is in fact installed, producing the exact incorrect-messaging outcome the module docstring's "Impact of False Negatives" section warns about (wt config show, the "installed but not active" hint).

Fix

Switch to filter_map(Result::ok) so a single unreadable line is skipped rather than truncating the whole scan, and move .enumerate() before the filter so a skipped line doesn't shift the 1-based line numbers of the lines below it (which feed unmatched_candidates / bypass_aliases hints).

Test

Adds test_scan_file_skips_non_utf8_line_before_integration: writes a .bashrc with a Latin-1 0xE9 byte on line 1 and a valid eval integration line on line 2, then asserts scan_file still matches the integration line and reports it at line 2. The test panics under the old map_while (the non-UTF-8 line stops iteration, matched_lines is empty, and scan_file returns None).

Low severity — shell configs are almost always UTF-8 — but a strictly-more-robust one-line change with no downside.

@worktrunk-bot worktrunk-bot added the nightly-cleanup Issues found by nightly code quality sweep label Jul 17, 2026
@max-sixty
max-sixty merged commit 3f0de45 into main Jul 17, 2026
37 of 47 checks passed
@max-sixty
max-sixty deleted the fix/shell-detection-nonutf8-truncation branch July 17, 2026 18:00
@max-sixty max-sixty mentioned this pull request Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nightly-cleanup Issues found by nightly code quality sweep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants