From bba03d14d4acbb9efdc1ac52649a9623c0f1cf5e Mon Sep 17 00:00:00 2001
From: GyDi <zzzgydi@gmail.com>
Date: Tue, 17 Jan 2023 19:51:02 +0800
Subject: [PATCH] fix: compatible with UTF8 BOM, close #283

---
 src-tauri/src/config/prfitem.rs | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src-tauri/src/config/prfitem.rs b/src-tauri/src/config/prfitem.rs
index 0bfeb37..5296e0e 100644
--- a/src-tauri/src/config/prfitem.rs
+++ b/src-tauri/src/config/prfitem.rs
@@ -282,8 +282,11 @@ impl PrfItem {
         let name = name.unwrap_or(filename.unwrap_or("Remote File".into()));
         let data = resp.text_with_charset("utf-8").await?;
 
+        // process the charset "UTF-8 with BOM"
+        let data = data.trim_start_matches('\u{feff}');
+
         // check the data whether the valid yaml format
-        let yaml = serde_yaml::from_str::<Mapping>(&data) //
+        let yaml = serde_yaml::from_str::<Mapping>(data)
             .context("the remote profile data is invalid yaml")?;
 
         if !yaml.contains_key("proxies") && !yaml.contains_key("proxy-providers") {
@@ -301,7 +304,7 @@ impl PrfItem {
             extra,
             option,
             updated: Some(chrono::Local::now().timestamp() as usize),
-            file_data: Some(data),
+            file_data: Some(data.into()),
         })
     }
 
-- 
GitLab