feat: base64 index-data to avoid misencoding (#421)

This commit is contained in:
sigoden
2024-07-22 08:02:32 +08:00
committed by GitHub
parent ec2b064a9a
commit ca5c3d7c54
4 changed files with 15 additions and 8 deletions

View File

@@ -1,3 +1,4 @@
use base64::{engine::general_purpose::STANDARD, Engine as _};
use indexmap::IndexSet;
use serde_json::Value;
@@ -48,7 +49,7 @@ pub fn retrieve_index_paths(content: &str) -> IndexSet<String> {
#[allow(dead_code)]
pub fn retrieve_edit_file(content: &str) -> Option<bool> {
let value = retrieve_json(content)?;
let value = retrieve_json(content).unwrap();
let value = value.get("editable").unwrap();
Some(value.as_bool().unwrap())
}
@@ -73,7 +74,9 @@ pub fn retrieve_json(content: &str) -> Option<Value> {
let end_index = line[start_content_index..].find(end_tag)?;
let end_content_index = start_content_index + end_index;
let value = line[start_content_index..end_content_index].parse().ok()?;
let value = &line[start_content_index..end_content_index];
let value = STANDARD.decode(value).ok()?;
let value = serde_json::from_slice(&value).ok()?;
Some(value)
}