Skip to content

Commit

Permalink
fix(chains): only guard fields should be overwritten (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 authored Mar 17, 2024
1 parent a3e99c3 commit 9046a1f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions backend/tauri/src/enhance/merge.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::{use_filter, use_lowercase};
use serde_yaml::{Mapping, Sequence, Value};
use tracing_attributes::instrument;

const MERGE_FIELDS: [&str; 6] = [
"prepend-rules",
Expand All @@ -10,11 +11,16 @@ const MERGE_FIELDS: [&str; 6] = [
"append-proxy-groups",
];

#[instrument(skip(merge, config))]
pub fn use_merge(merge: Mapping, mut config: Mapping) -> Mapping {
tracing::trace!("original config: {:#?}", config);
tracing::trace!("merge: {:#?}", merge);
// 直接覆盖原字段
use_lowercase(merge.clone())
.into_iter()
.filter(|(key, _)| !MERGE_FIELDS.contains(&key.as_str().unwrap_or_default()))
.for_each(|(key, value)| {
tracing::debug!("override: key: {:?}, value: {:?}", key, value);
config.insert(key, value);
});

Expand Down Expand Up @@ -51,6 +57,7 @@ pub fn use_merge(merge: Mapping, mut config: Mapping) -> Mapping {

config.insert(key_val, Value::from(list));
});
tracing::trace!("merged config: {:#?}", config);
config
}

Expand Down
10 changes: 7 additions & 3 deletions backend/tauri/src/enhance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ pub fn enhance() -> (Mapping, Vec<String>, HashMap<String, ResultLog>) {
});

// 合并默认的config
for (key, value) in clash_config.into_iter() {
config.insert(key, value);
}
clash_config
.iter()
// only guarded fields should be overwritten
.filter(|(k, _)| HANDLE_FIELDS.contains(&k.as_str().unwrap_or_default()))
.for_each(|(key, value)| {
config.insert(key.to_owned(), value.clone());
});

let clash_fields = use_clash_fields();

Expand Down

0 comments on commit 9046a1f

Please sign in to comment.