Преглед изворни кода

feat: check the remote profile

GyDi пре 3 година
родитељ
комит
9694af82f4
1 измењених фајлова са 6 додато и 0 уклоњено
  1. 6 0
      src-tauri/src/core/prfitem.rs

+ 6 - 0
src-tauri/src/core/prfitem.rs

@@ -1,6 +1,7 @@
 use crate::utils::{dirs, help, tmpl};
 use anyhow::{bail, Context, Result};
 use serde::{Deserialize, Serialize};
+use serde_yaml::Mapping;
 use std::fs;
 
 #[derive(Debug, Clone, Deserialize, Serialize)]
@@ -228,6 +229,11 @@ impl PrfItem {
     let name = name.unwrap_or(uid.clone());
     let data = resp.text_with_charset("utf-8").await?;
 
+    // check the data whether the valid yaml format
+    if !serde_yaml::from_str::<Mapping>(&data).is_ok() {
+      bail!("the remote profile data is not valid yaml");
+    }
+
     Ok(PrfItem {
       uid: Some(uid),
       itype: Some("remote".into()),