diff options
author | dag-h <dagharju@protonmail.com> | 2022-09-06 19:08:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-06 19:08:38 +0200 |
commit | 08386daa3ae9a149ac27261579745cad11993b06 (patch) | |
tree | 5188030fe54bd96155451e08776597e9165ac0c3 /src/printer.rs | |
parent | 0e03dce130aac185190d5176c2ea075aaddd5ed2 (diff) |
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>
Diffstat (limited to 'src/printer.rs')
-rw-r--r-- | src/printer.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/printer.rs b/src/printer.rs index 3f7f1e09..4f962df9 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -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 } }; |