-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Handled UTF-8 BOM #1285
Handled UTF-8 BOM #1285
Conversation
Fixed rust-lang#1155 .
使用 YSLib-wiki.hg 版本 b1d91974e33d ,符号链接到 src 。 依赖 mdBook 0.4.1 修改版,参见 rust-lang/mdBook#1285 。 Signed-off-by: FrankHB <frankhb1989@gmail.com>
使用 YSLib-wiki.hg 版本 b1d91974e33d ,符号链接到 src 。 依赖 mdBook 0.4.1 修改版,参见 rust-lang/mdBook#1285 。 Signed-off-by: FrankHB <frankhb1989@gmail.com>
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 for the PR! Can you also add a test for this?
src/book/book.rs
Outdated
@@ -264,6 +264,10 @@ fn load_chapter<P: AsRef<Path>>( | |||
format!("Unable to read \"{}\" ({})", link.name, location.display()) | |||
})?; | |||
|
|||
if content.as_bytes().starts_with(b"\xef\xbb\xbf") { | |||
content = content[3..].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.
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>
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!
使用 YSLib-wiki.hg 版本 e1f073d604e6 ,符号链接到 src 。 依赖 mdBook 0.4.1 修改版,参见 rust-lang/mdBook#1285 。 Signed-off-by: FrankHB <frankhb1989@gmail.com>
Fixed #1155 .