From 59762520ccfdcd93e889bc7fcc4e8ccc94c20f45 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Fri, 4 Dec 2026 01:48:32 +0800 Subject: [PATCH] fix(profile-store): refresh native Unix body filenames --- crates/clash-verge-profile-store/src/lib.rs | 6 +++++- crates/clash-verge-profile-store/tests/legacy_refresh.rs | 7 ++++--- src-tauri/src/config/profile_storage.rs | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/clash-verge-profile-store/src/lib.rs b/crates/clash-verge-profile-store/src/lib.rs index 729124cac..0dc6a695a 100644 --- a/crates/clash-verge-profile-store/src/lib.rs +++ b/crates/clash-verge-profile-store/src/lib.rs @@ -433,7 +433,11 @@ fn read_decision(path: &Path) -> Result { } fn validate_filename(file: &str) -> Result<()> { - if file.is_empty() || matches!(file, "." | "..") || file.contains(['/', '\\', ':', '\0']) { + if file.is_empty() + || matches!(file, "." | "..") + || file.contains(['/', '\\', '\0']) + || (cfg!(windows) && file.contains(':')) + { return Err(StoreError::InvalidFilename); } #[cfg(windows)] diff --git a/crates/clash-verge-profile-store/tests/legacy_refresh.rs b/crates/clash-verge-profile-store/tests/legacy_refresh.rs index 53e16d537..68f0657cc 100644 --- a/crates/clash-verge-profile-store/tests/legacy_refresh.rs +++ b/crates/clash-verge-profile-store/tests/legacy_refresh.rs @@ -30,18 +30,19 @@ fn refresh_creates_missing_body_for_legacy_index() -> Result<(), clash_verge_pro #[cfg(unix)] #[test] -fn refresh_allows_an_unrelated_unix_filename() -> Result<(), clash_verge_profile_store::StoreError> { +fn refresh_preserves_native_unix_filenames() -> Result<(), clash_verge_profile_store::StoreError> { let dir = tempfile::tempdir()?; let root = dir.path(); fs::create_dir(root.join("profiles"))?; - fs::write(root.join("profiles/r.yaml"), b"old")?; + fs::write(root.join("profiles/remote:old.yaml"), b"old")?; fs::write(root.join("profiles/office:old.yaml"), b"local")?; - let old = "items:\n- {uid: r, type: remote, file: r.yaml, updated: 1}\n- {uid: l, type: local, file: 'office:old.yaml'}\n"; + let old = "items:\n- {uid: r, type: remote, file: 'remote:old.yaml', updated: 1}\n- {uid: l, type: local, file: 'office:old.yaml'}\n"; fs::write(root.join("profiles.yaml"), old)?; let candidate = serde_yaml_ng::from_str(&old.replace("updated: 1", "updated: 2"))?; let outcome = Session::open(root)?.commit_refresh("r", &candidate, b"new"); assert!(matches!(outcome, CommitOutcome::Committed), "{outcome:?}"); + assert_eq!(fs::read(root.join("profiles/remote:old.yaml"))?, b"new"); assert_eq!(fs::read(root.join("profiles/office:old.yaml"))?, b"local"); Ok(()) } diff --git a/src-tauri/src/config/profile_storage.rs b/src-tauri/src/config/profile_storage.rs index d2f8f701b..6d2cda3e5 100644 --- a/src-tauri/src/config/profile_storage.rs +++ b/src-tauri/src/config/profile_storage.rs @@ -159,7 +159,8 @@ async fn commit_recoverable_refresh( })?; let item = candidate.get_item(&uid)?; if let Some(file) = item.file.as_deref() - && !file.contains(['/', '\\', ':', '\0']) + && !file.contains(['/', '\\', '\0']) + && (!cfg!(windows) || !file.contains(':')) && !matches!(file, "" | "." | "..") { let path = root.join("profiles").join(file);