This commit is contained in:
sxyazi 2025-07-31 00:42:49 +08:00
parent b77a92bf67
commit 92a6c8a895
No known key found for this signature in database
3 changed files with 13 additions and 10 deletions

View file

@ -75,7 +75,7 @@ impl Trigger {
} }
#[cfg(windows)] #[cfg(windows)]
const SEP: [char; 2] = ['/', '\\']; const SEP: &[char] = &['/', '\\'];
#[cfg(not(windows))] #[cfg(not(windows))]
const SEP: char = std::path::MAIN_SEPARATOR; const SEP: char = std::path::MAIN_SEPARATOR;

View file

@ -75,17 +75,20 @@ fn _expand_url(url: &Url) -> Cow<'_, Url> {
.and_then(env::var_os) .and_then(env::var_os)
.map_or_else(|| caps.get(0).unwrap().as_bytes().to_owned(), |s| s.into_encoded_bytes()) .map_or_else(|| caps.get(0).unwrap().as_bytes().to_owned(), |s| s.into_encoded_bytes())
}); });
if matches!(b, Cow::Borrowed(_)) {
return url.into();
}
let p = unsafe { PathBuf::from(OsString::from_encoded_bytes_unchecked(b.into_owned())) }; let path: Cow<_> = unsafe {
if let Some(rest) = p.strip_prefix("~").ok().filter(|_| local) { match b {
Cow::Borrowed(b) => Path::new(OsStr::from_encoded_bytes_unchecked(b)).into(),
Cow::Owned(b) => PathBuf::from(OsString::from_encoded_bytes_unchecked(b)).into(),
}
};
if let Some(rest) = path.strip_prefix("~").ok().filter(|_| local) {
url.with(clean_path(&dirs::home_dir().unwrap_or_default().join(rest))).into() url.with(clean_path(&dirs::home_dir().unwrap_or_default().join(rest))).into()
} else if p.is_absolute() { } else if path.is_absolute() {
url.with(clean_path(&p)).into() url.with(clean_path(&path)).into()
} else { } else {
clean_url(CWD.load().join(p)) clean_url(CWD.load().join(path))
} }
} }

View file

@ -90,6 +90,6 @@ impl Pattern for char {
fn predicate(&self, byte: u8) -> bool { *self == byte as char } fn predicate(&self, byte: u8) -> bool { *self == byte as char }
} }
impl Pattern for [char] { impl Pattern for &[char] {
fn predicate(&self, byte: u8) -> bool { self.contains(&(byte as char)) } fn predicate(&self, byte: u8) -> bool { self.contains(&(byte as char)) }
} }