-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strip BOM from output in interactive mode #1938
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for working on this! I took a high level look and had a high level comment.
BOM is now stripped from all non- |
Sorry for leaving this hanging for so long. I think this actually looks quite good! I have one minor question: Is there any chance that this would interfere with any of the other Or does this interfere/interact somehow with |
// 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(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there is an alternative implementation where we do not have to allocate a new string? by operating on &str
instead of String
.
But .. this is only relevant for files starting with a BOM. So maybe it's not the most urgent question.
Fixed the merge conflicts. |
Looks like tests are failing in Mac and Windows, but I will be to review this PR once that has been sorted out (I did a quick try at fixing the failures myself but it did not seem trivial to fix) |
Indeed. Two tests on macOS and Windows where failing for two different reasons:
In addition, the "Run tests with updated syntaxes and themes" check was failing because we have one syntax test with a UTF-16 BOM (PowerShell). Previously, The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Phenomenal! Let's merge this then! Code looks good to me 👍
Fixes #1922
This is my first contribution to an open source project so I apologize in advance for any misunderstandings!
I tried finding somewhere where the output is known to be shown in an interactive mode, and
InteractivePrinter
looked right on. Removed the BOM if present on the first line. Also made sure the BOM is not stripped if output is piped to a file/other program.Contents of first line copied from
bat Program.cs.txt
(see #1922 for example file):Contents of file obtained from
bat Program.cs.txt > test.txt
:The
utf16
test then fails since it expects the output to contain the BOM. As far as I can tell the test runsbat
in interactive mode, so I assumed this to be incorrect now. I changed the expected test output to not contain the BOM anymore.I have probably missed some important things to consider, and there are probably better ways to do this than
std::str::replace
.