mirror of
https://github.com/sharkdp/bat.git
synced 2025-09-02 03:12:25 +01:00
Strip BOM from output in interactive mode (#1938)
* Strip BOM from output in interactive mode * Strip BOM when not loop_through, add regression tests * Update CHANGELOG.md * Only strip BOM from beginning of first line * Fix integration test on macOS that relied on color scheme * Fix integration test on Windows that relied on detected terminal width * Fix syntax test that was failing due to a previously wrong (now fixed) highlighting Co-authored-by: David Peter <mail@david-peter.de> Co-authored-by: Martin Nordholts <enselic@gmail.com>
This commit is contained in:
@@ -419,7 +419,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
||||
let line = if self.config.show_nonprintable {
|
||||
replace_nonprintable(line_buffer, self.config.tab_width)
|
||||
} else {
|
||||
match self.content_type {
|
||||
let line = match self.content_type {
|
||||
Some(ContentType::BINARY) | None => {
|
||||
return Ok(());
|
||||
}
|
||||
@@ -430,6 +430,15 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
||||
.decode(line_buffer, DecoderTrap::Replace)
|
||||
.map_err(|_| "Invalid UTF-16BE")?,
|
||||
_ => String::from_utf8_lossy(line_buffer).to_string(),
|
||||
};
|
||||
// Remove byte order mark from the first line if it exists
|
||||
if line_number == 1 {
|
||||
match line.strip_prefix('\u{feff}') {
|
||||
Some(stripped) => stripped.to_string(),
|
||||
None => line,
|
||||
}
|
||||
} else {
|
||||
line
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user