Skip to content

Commit afc6873

Browse files
committed
Bug fix: UTF8-BOM file supported
1 parent bcf4855 commit afc6873

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

oneport/src/config.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ async fn find_config(file: Option<String>) -> Option<String> {
5252
Ok(v) => v,
5353
_ => return None,
5454
};
55-
let config = String::from_utf8(config).unwrap_or_default();
55+
// BOM 编码的 UTF-8 字符串将从以下三个字节开始:EF BB BF
56+
// 从文件/流中提取字符串时,必须忽略这些字节(如果存在)。
57+
let config = if config[..3] == vec![0xEF, 0xBB, 0xBF] {
58+
&config[3..]
59+
} else {
60+
&config
61+
};
62+
let config = String::from_utf8_lossy(config).to_string();
5663
Some(config)
5764
}
5865
None => {

0 commit comments

Comments
 (0)