mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-04 21:30:06 +08:00
fix(profile-store): refresh native Unix body filenames
This commit is contained in:
@@ -433,7 +433,11 @@ fn read_decision(path: &Path) -> Result<Decision> {
|
||||
}
|
||||
|
||||
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)]
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user