Repository navigation
Ignore a UTF-8 BOM at the start of the config file - #4103
Conversation
e50b381 to
d760da4
Compare
rahul05ranjan
left a comment
There was a problem hiding this comment.
Verified the failure mechanism end to end:
read_to_stringdoesn't drop the BOM bytes, so the content starts with U+FEFF.- U+FEFF has Unicode category
Cf, notWhite_Space, so theline.trim()inget_args_from_str(config.rs) keeps it (I checked the whitespace semantics against the Unicode property — both Rust'strimand other languages followingWhite_Spacekeep it). - That means a
\u{feff}# commentline fails thestarts_with('#')filter (it starts with U+FEFF) and gets split into bogus file arguments, and\u{feff}--style=...becomes an unknown option. Both match the reported symptom.
Stripping at each fs::read_to_string call site is the right placement: it's applied to the system config and the user config independently, which matters because the two contents are concatenated — a single strip after concatenation would miss a BOM on the user config that lands mid-string. A BOM in the middle of a file (not at offset 0) stays untouched, which is correct for strip_prefix.
One observation, not a blocker: BAT_OPTS goes through get_args_from_str directly, so a hypothetical BOM there would still break — but env vars are set programmatically, so the file-read sites are the only realistic source. If you ever wanted belt-and-braces, moving the strip into get_args_from_str would cover both paths at once.
The two-case test (BOM before an option, BOM before a comment line) plus the \r\n line endings mirrors what Set-Content -Encoding UTF8 actually produces. LGTM.
d760da4 to
7df6406
Compare
Resolve the CHANGELOG conflict with sharkdp#4102 and sharkdp#4103: keep their new entries, keep this PR's sharkdp#4084 entry, and point the UTF-16BE entry back at sharkdp#4076 (the merge of sharkdp#4102 had filled its placeholder with sharkdp#4102). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VVn4SeAXPsUajXT2rtHQfo
Config files saved by Windows PowerShell 5.1 (
Set-Content -Encoding UTF8) start with a UTF-8 BOM.line.trim()keeps U+FEFF, so the first line becomes an argument like\u{feff}--style=plain, or a# commentline turns into file arguments, and every invocation fails with'\u{feff}#': The system cannot find the file specified. A leading BOM is now stripped from each config file (system and user) before parsing.config_file_with_utf8_bom(BOM before an option and before a comment, with CRLF) fails before the change and passes after.cargo test, clippy and fmt pass.