From 7df6406ca93bf114de279fbcaccd4160c9c41854 Mon Sep 17 00:00:00 2001 From: jaeminbird Date: Thu, 29 Oct 2026 04:52:54 -0400 Subject: [PATCH 1/3] Ignore a UTF-8 BOM at the start of the config file --- CHANGELOG.md | 1 + src/bin/bat/config.rs | 10 ++++++++-- tests/integration_tests.rs | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1815da8..3fe8d024 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ ## Bugfixes - Report `BAT_CONFIG_DIR` in `bat --diagnostic`, so bug reports show a config directory that overrides `$XDG_CONFIG_HOME`. See #4068 (@ump45nose) +- Ignore a UTF-8 byte order mark at the start of the config file instead of treating it as part of the first argument, see #4103 (@jaeminbird) - Fix `bat` hanging forever on JavaScript (and Svelte) code where an expression is followed by a block comment, e.g. `a /* x */`. Closes #4080, see #4091 (@NavpreetSSidhu) - Fix the first line of UTF-16BE input swallowing the second line, which broke line numbers, `--line-range` and highlighting, see #XXXX (@cindykrafft) - Exit quietly with status 0 instead of panicking when stdout is closed early (broken pipe) on auxiliary output paths such as `--completion`, `--config-file`, `--diagnostic`, `--generate-config-file`, `--set-terminal-title` and `cache --build`/`--clear`, matching the main output path since #232, closes #4034, see #4035 (@Mathjk) diff --git a/src/bin/bat/config.rs b/src/bin/bat/config.rs index 863aa3d7..3a7e2b83 100644 --- a/src/bin/bat/config.rs +++ b/src/bin/bat/config.rs @@ -110,7 +110,7 @@ pub fn get_args_from_config_file() -> Result, shell_words::ParseEr let user_config = config_file(); if let Ok(c) = fs::read_to_string(&system_config) { - config.push_str(&c); + config.push_str(strip_bom(&c)); config.push('\n'); } @@ -118,7 +118,7 @@ pub fn get_args_from_config_file() -> Result, shell_words::ParseEr // which can happen when BAT_CONFIG_DIR is set to e.g. "/etc/bat". See #3589. if !same_file(&system_config, &user_config) { if let Ok(c) = fs::read_to_string(&user_config) { - config.push_str(&c); + config.push_str(strip_bom(&c)); } } @@ -136,6 +136,12 @@ pub fn get_args_from_env_opts_var() -> Option, shell_words: env::var("BAT_OPTS").ok().map(|s| get_args_from_str(&s)) } +/// Editors on Windows (e.g. `Set-Content -Encoding UTF8` in Windows PowerShell) +/// may prepend a UTF-8 byte order mark, which would otherwise end up in the first argument. +fn strip_bom(content: &str) -> &str { + content.strip_prefix('\u{feff}').unwrap_or(content) +} + fn get_args_from_str(content: &str) -> Result, shell_words::ParseError> { let args_per_line = content .split('\n') diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 1d252015..2a2e97a5 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1786,6 +1786,28 @@ fn help_works_with_invalid_config() { .stdout(predicate::str::contains("A cat(1) clone with wings")); } +#[test] +fn config_file_with_utf8_bom() { + let tmp_dir = tempdir().expect("can create temporary directory"); + let tmp_config_path = tmp_dir.path().join("config"); + + for config in [ + "\u{feff}--style=numbers\r\n", + "\u{feff}# comment\r\n--style=numbers\r\n", + ] { + std::fs::write(&tmp_config_path, config).expect("can write config file"); + + bat_with_config() + .env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap()) + .arg("test.txt") + .arg("--decorations=always") + .assert() + .success() + .stdout(" 1 hello world\n") + .stderr(""); + } +} + #[test] fn help_uses_valid_config() { let tmp_dir = tempdir().expect("can create temporary directory"); From f059c8da388bb37b3d8c5159c7dfc277a93d9a22 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Nov 2026 03:03:56 +0000 Subject: [PATCH 2/3] build(deps): bump vedantmgoyal9/winget-releaser Bumps [vedantmgoyal9/winget-releaser](https://github.com/vedantmgoyal9/winget-releaser) from a8fff44b123f115ce4c21543edf8b677376fc7e0 to b7370d4d152efdce803a26cc6ca9eee58cb2ad54. - [Release notes](https://github.com/vedantmgoyal9/winget-releaser/releases) - [Commits](https://github.com/vedantmgoyal9/winget-releaser/compare/a8fff44b123f115ce4c21543edf8b677376fc7e0...b7370d4d152efdce803a26cc6ca9eee58cb2ad54) --- updated-dependencies: - dependency-name: vedantmgoyal9/winget-releaser dependency-version: b7370d4d152efdce803a26cc6ca9eee58cb2ad54 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index fc807718..138bc575 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -458,7 +458,7 @@ jobs: needs: build if: startsWith(github.ref, 'refs/tags/v') steps: - - uses: vedantmgoyal9/winget-releaser@a8fff44b123f115ce4c21543edf8b677376fc7e0 + - uses: vedantmgoyal9/winget-releaser@b7370d4d152efdce803a26cc6ca9eee58cb2ad54 with: identifier: sharkdp.bat installers-regex: '-pc-windows-msvc\.zip$' From b5281b5a4f756b8ac3fd5abd201e6625fc8a4c7b Mon Sep 17 00:00:00 2001 From: huang <13165998033@163.com> Date: Thu, 29 Oct 2026 16:06:32 +0800 Subject: [PATCH 3/3] fix(cli): allow valued options to be repeated The config file is prepended to the command line, so an option set in both places is passed twice. Boolean flags were made repeatable in #3912, but options that take a value were missed: --binary, --italic-text, --nonprintable-notation, --fallback-syntax and --squeeze-limit were rejected with 'cannot be used multiple times', which aborts bat with exit code 2 before it reads any input. Add self-overrides so that the last occurrence wins, matching the behavior of --color, --theme, --wrap, --tabs and friends. --- CHANGELOG.md | 3 ++- src/bin/bat/clap_app.rs | 5 +++++ tests/integration_tests.rs | 45 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1815da8..9cc8f32a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,10 +30,11 @@ ## Bugfixes - Report `BAT_CONFIG_DIR` in `bat --diagnostic`, so bug reports show a config directory that overrides `$XDG_CONFIG_HOME`. See #4068 (@ump45nose) - Fix `bat` hanging forever on JavaScript (and Svelte) code where an expression is followed by a block comment, e.g. `a /* x */`. Closes #4080, see #4091 (@NavpreetSSidhu) -- Fix the first line of UTF-16BE input swallowing the second line, which broke line numbers, `--line-range` and highlighting, see #XXXX (@cindykrafft) +- Fix the first line of UTF-16BE input swallowing the second line, which broke line numbers, `--line-range` and highlighting, see #4102 (@cindykrafft) - Exit quietly with status 0 instead of panicking when stdout is closed early (broken pipe) on auxiliary output paths such as `--completion`, `--config-file`, `--diagnostic`, `--generate-config-file`, `--set-terminal-title` and `cache --build`/`--clear`, matching the main output path since #232, closes #4034, see #4035 (@Mathjk) - Track strikethrough (SGR 9 / 29) in the ANSI style tracker so it is re-emitted like bold, dim, italic, and underline, and is no longer dropped after the first highlighted token when displaying ANSI input with syntax highlighting, see #4015 (@mikehasa) - Allow boolean flags to be given more than once, so that a flag set in the config file can also be passed on the command line without erroring, see #3912 (@logarithmone1128) +- Allow options that take a value (`--binary`, `--italic-text`, `--nonprintable-notation`, `--fallback-syntax`, `--squeeze-limit`) to be given more than once, so that a value from the config file can be overridden on the command line, see #4102 (@Huang-404-Q) - Use parsed CLI arguments to detect number flags, see #3908 (@cuishuang) - Detect binary content beyond the first line, preventing encrypted files with early line breaks from being treated as text. Closes #3554, see #3877 (@Matei02355) - Use the last occurrence of numbering and plain flags in combined short arguments, see #3897 (@cuishuang) diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index 9d57fc92..3d626d53 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -65,6 +65,7 @@ pub fn build_app(interactive_output: bool) -> Command { .arg( Arg::new("nonprintable-notation") .long("nonprintable-notation") + .overrides_with("nonprintable-notation") .action(ArgAction::Set) .default_value("unicode") .value_parser(["unicode", "caret"]) @@ -81,6 +82,7 @@ pub fn build_app(interactive_output: bool) -> Command { .arg( Arg::new("binary") .long("binary") + .overrides_with("binary") .action(ArgAction::Set) .default_value("no-printing") .value_parser(["no-printing", "as-text"]) @@ -125,6 +127,7 @@ pub fn build_app(interactive_output: bool) -> Command { .arg( Arg::new("fallback-syntax") .long("fallback-syntax") + .overrides_with("fallback-syntax") .visible_alias("fallback-language") .help("Set a fallback language for undetected syntaxes.") .long_help( @@ -317,6 +320,7 @@ pub fn build_app(interactive_output: bool) -> Command { .arg( Arg::new("italic-text") .long("italic-text") + .overrides_with("italic-text") .value_name("when") .value_parser(["always", "never"]) .default_value("never") @@ -484,6 +488,7 @@ pub fn build_app(interactive_output: bool) -> Command { .arg( Arg::new("squeeze-limit") .long("squeeze-limit") + .overrides_with("squeeze-limit") .value_parser(|s: &str| s.parse::().map_err(|_| "Requires a non-negative number".to_owned())) .long_help("Set the maximum number of consecutive empty lines to be printed.") .hide_short_help(true) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 1d252015..9e56ddbe 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -729,6 +729,51 @@ fn boolean_flag_in_config_and_on_command_line() { .success(); } +#[test] +fn repeated_valued_option_is_accepted() { + // Options that take a value must be repeatable (last value wins) just like + // boolean flags, otherwise a value from the config file cannot be + // overridden on the command line. + for options in [ + ["--binary=as-text", "--binary=no-printing"], + ["--italic-text=always", "--italic-text=never"], + [ + "--nonprintable-notation=unicode", + "--nonprintable-notation=caret", + ], + ["--fallback-syntax=bash", "--fallback-syntax=json"], + ["--squeeze-limit=5", "--squeeze-limit=2"], + ] { + bat() + .arg("test.txt") + .args(options) + .assert() + .success() + .stdout("hello world\n"); + } +} + +#[test] +fn valued_option_in_config_can_be_overridden_on_command_line() { + // The config file is prepended to the command line, so a value given in + // both places used to be rejected as "cannot be used multiple times". + let tmp_dir = tempdir().expect("can create temporary directory"); + let tmp_config_path = tmp_dir.path().join("config"); + std::fs::write(&tmp_config_path, "--binary=as-text").expect("can write config file"); + + bat_with_config() + .env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap()) + .arg("test.binary") + .arg("--binary=no-printing") + .arg("--color=always") + .arg("--decorations=never") + .arg("--paging=never") + .assert() + .success() + .stdout(predicate::str::contains("Binary content from")) + .stdout(predicate::str::contains("\0").not()); +} + #[test] fn squeeze_blank() { bat()