mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix: avoid expanding paths for non-regular URLs
This commit is contained in:
parent
f3e45d4a47
commit
27255b22de
4 changed files with 14 additions and 13 deletions
|
|
@ -19,11 +19,11 @@ pub struct Boot {
|
||||||
|
|
||||||
impl Boot {
|
impl Boot {
|
||||||
fn parse_entry(entry: Option<PathBuf>) -> (PathBuf, Option<OsString>) {
|
fn parse_entry(entry: Option<PathBuf>) -> (PathBuf, Option<OsString>) {
|
||||||
let Some(entry) = entry else {
|
let entry = match entry {
|
||||||
return (env::current_dir().unwrap(), None);
|
Some(p) => expand_path(p),
|
||||||
|
None => return (env::current_dir().unwrap(), None),
|
||||||
};
|
};
|
||||||
|
|
||||||
let entry = expand_path(entry);
|
|
||||||
let parent = entry.parent();
|
let parent = entry.parent();
|
||||||
if parent.is_none() || entry.is_dir() {
|
if parent.is_none() || entry.is_dir() {
|
||||||
return (entry, None);
|
return (entry, None);
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,12 @@ pub struct Opt {
|
||||||
|
|
||||||
impl From<&Exec> for Opt {
|
impl From<&Exec> for Opt {
|
||||||
fn from(e: &Exec) -> Self {
|
fn from(e: &Exec) -> Self {
|
||||||
Self {
|
let mut target = Url::from(e.args.first().map(|s| s.as_str()).unwrap_or(""));
|
||||||
target: Url::from(expand_path(e.args.first().map(|s| s.as_str()).unwrap_or(""))),
|
if target.is_regular() {
|
||||||
interactive: e.named.contains_key("interactive"),
|
target.set_path(expand_path(&target))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Self { target, interactive: e.named.contains_key("interactive") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<Url> for Opt {
|
impl From<Url> for Opt {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,12 @@ pub struct Opt {
|
||||||
|
|
||||||
impl From<&Exec> for Opt {
|
impl From<&Exec> for Opt {
|
||||||
fn from(e: &Exec) -> Self {
|
fn from(e: &Exec) -> Self {
|
||||||
Self { target: Url::from(expand_path(e.args.first().map(|s| s.as_str()).unwrap_or(""))) }
|
let mut target = Url::from(e.args.first().map(|s| s.as_str()).unwrap_or(""));
|
||||||
|
if target.is_regular() {
|
||||||
|
target.set_path(expand_path(&target))
|
||||||
|
}
|
||||||
|
|
||||||
|
Self { target }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<Url> for Opt {
|
impl From<Url> for Opt {
|
||||||
|
|
|
||||||
|
|
@ -38,12 +38,6 @@ fn _expand_path(p: &Path) -> PathBuf {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn expand_path(p: impl AsRef<Path>) -> PathBuf { _expand_path(p.as_ref()) }
|
pub fn expand_path(p: impl AsRef<Path>) -> PathBuf { _expand_path(p.as_ref()) }
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn expand_url(mut u: Url) -> Url {
|
|
||||||
u.set_path(_expand_path(&u));
|
|
||||||
u
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn ends_with_slash(p: &Path) -> bool {
|
pub fn ends_with_slash(p: &Path) -> bool {
|
||||||
// TODO: uncomment this when Rust 1.74 is released
|
// TODO: uncomment this when Rust 1.74 is released
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue