diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cc3df4e..2e32b651 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Other +- Document `StripAnsiMode` and its variants in rustdoc, see #4067 (@ump45nose) - Update Cargo dependencies to resolve current RustSec advisories, see #3861 (@TyceHerrman) - Add instructions for removing fish help abbreviations to README, see #3655 (@claw-explorer). Closes #3536 - Add .NET slnx extension, see #3682 (@ltrzesniewski) @@ -26,6 +27,7 @@ ## Bugfixes - Report `BAT_CONFIG_DIR` in `bat --diagnostic`, so bug reports show a config directory that overrides `$XDG_CONFIG_HOME`. See #4068 (@ump45nose) +- 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) - 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) @@ -87,6 +89,7 @@ - Add syntax highlighting for `Caddyfile` #3789 (@CosmicHorrorDev) - Include `.code-workspace` as a JSON extension #3809 (@dhruvkb) - Add syntax mapping for DNF repo configuration files, see #3814 (@injust) +- Add syntax mapping for Podman `.quadlets` files, see #4069 (@injust) ## Themes diff --git a/src/input.rs b/src/input.rs index d79c8198..7fa2bdff 100644 --- a/src/input.rs +++ b/src/input.rs @@ -291,7 +291,12 @@ impl<'a> InputReader<'a> { if content_type == Some(ContentType::UTF_16LE) { read_utf16_line(&mut reader, &mut first_line, 0x00, 0x0A)?; - } else if content_type == Some(ContentType::UTF_16BE) { + } else if content_type == Some(ContentType::UTF_16BE) + // In UTF-16BE a newline is encoded as 0x00 0x0A, so `read_until(b'\n')` above + // may already have read a complete first line. Only keep reading if it did not + // (e.g. the 0x0A byte was part of another character such as U+4E0A). + && !(first_line.len() % 2 == 0 && first_line.ends_with(&[0x00, 0x0A])) + { read_utf16_line(&mut reader, &mut first_line, 0x0A, 0x00)?; } diff --git a/src/preprocessor.rs b/src/preprocessor.rs index a9b8e712..c19d0092 100644 --- a/src/preprocessor.rs +++ b/src/preprocessor.rs @@ -302,11 +302,21 @@ pub fn strip_overstrike(line: &str, first_backspace: usize) -> String { output } +/// Specify when to strip ANSI escape sequences from the input. +/// +/// Used for both the `--strip-ansi` and the `--sanitize` option, the latter +/// implying the former with the same value. #[derive(Debug, PartialEq, Clone, Copy, Default)] pub enum StripAnsiMode { + /// Keep escape sequences in the output #[default] Never, + + /// Strip escape sequences from the output Always, + + /// Strip escape sequences unless the syntax highlighting language is plain + /// text, in which case they may be part of what the input wants to display Auto, } diff --git a/src/syntax_mapping/builtins/linux/50-podman-quadlet.toml b/src/syntax_mapping/builtins/linux/50-podman-quadlet.toml index 1544b52f..a744a69e 100644 --- a/src/syntax_mapping/builtins/linux/50-podman-quadlet.toml +++ b/src/syntax_mapping/builtins/linux/50-podman-quadlet.toml @@ -1,5 +1,6 @@ # see `man quadlet` [mappings] "INI" = [ + "*.quadlets", "**/containers/systemd/**/*.{container,volume,network,kube,image,build,pod,artifact}", ] diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index f4c21815..1d252015 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -2102,6 +2102,19 @@ fn utf16be() { .stdout(" 1 上一伊刀\n 2 foo bar\n 3 hello world\n"); } +#[test] +fn utf16be_first_line_not_merged_with_second() { + // The first line of a UTF-16BE file must not swallow the second line + bat() + .arg("--decorations=always") + .arg("--style=numbers") + .arg("--color=never") + .arg("test_UTF-16BE.txt") + .assert() + .success() + .stdout(" 1 hello world\n 2 this is a test\n"); +} + // Regression test for https://github.com/sharkdp/bat/issues/1922 #[test] fn bom_not_stripped_in_loop_through_mode() {