Handled UTF-8 BOM#1285
Conversation
Fixed rust-lang#1155 .
ehuss
left a comment
There was a problem hiding this comment.
Thanks for the PR! Can you also add a test for this?
| })?; | ||
|
|
||
| if content.as_bytes().starts_with(b"\xef\xbb\xbf") { | ||
| content = content[3..].to_string() |
There was a problem hiding this comment.
Just to avoid the extra allocation, perhaps this could be content.replace_range(..3, "");
Signed-off-by: FrankHB <frankhb1989@gmail.com>
|
Not sure where should be the test. Is an additional BOM in |
|
I'm a little concerned about having invisible bytes in a file. My only other idea is to create a simple 1-chapter book in a temp directory like |
|
Sorry, I don't get the point of the temp directory. As of the subtleness... I largely agree. Nevertheless, I can use a hex editor to make sure only the BOM is inserted exactly. Anyway, the visible part of the file has already warned us about this. (Or one more visible warning about invisible bytes?) |
|
Creating a book in Rust code (and writing it to a temp directory) would allow writing the content in a Rust string where the characters can be escaped and explicit. For example, |
Signed-off-by: FrankHB <frankhb1989@gmail.com>
Fixed #1155 .