diff --git a/yazi-binding/src/url.rs b/yazi-binding/src/url.rs index 95a82ad6..07d1f333 100644 --- a/yazi-binding/src/url.rs +++ b/yazi-binding/src/url.rs @@ -157,8 +157,8 @@ impl UserData for Url { Ok(url.map(Self::new)) }); - methods.add_function_mut("into_search", |_, (ud, frag): (AnyUserData, String)| { - Ok(Self::new(ud.take::()?.inner.into_search(frag))) + methods.add_function_mut("into_search", |_, (ud, frag): (AnyUserData, mlua::String)| { + Ok(Self::new(ud.take::()?.inner.into_search(frag.to_str()?))) }); methods.add_meta_method(MetaMethod::Eq, |_, me, other: UrlRef| Ok(me.inner == other.inner)); diff --git a/yazi-fs/src/path.rs b/yazi-fs/src/path.rs index 72187057..69f152b0 100644 --- a/yazi-fs/src/path.rs +++ b/yazi-fs/src/path.rs @@ -1,7 +1,7 @@ use std::{borrow::Cow, env, ffi::{OsStr, OsString}, future::Future, io, path::{Path, PathBuf}}; use anyhow::{Result, bail}; -use yazi_shared::url::Url; +use yazi_shared::url::{Loc, Url}; use crate::{CWD, services}; @@ -35,11 +35,12 @@ fn _clean_path(path: &Path) -> PathBuf { #[inline] pub fn expand_path(p: impl AsRef) -> PathBuf { _expand_path(p.as_ref()) } -// FIXME: keep the original scheme of the Url #[inline] pub fn expand_url<'a>(url: impl Into>) -> Cow<'a, Url> { let u: Cow<'a, Url> = url.into(); - if let Some(p) = u.as_path() { Url::from(_expand_path(p)).into() } else { u } + let Some(p) = u.as_path() else { return u }; + + Url { loc: Loc::with(u.loc.base(), _expand_path(p)), scheme: u.scheme.clone() }.into() } fn _expand_path(p: &Path) -> PathBuf { diff --git a/yazi-shared/src/url/scheme.rs b/yazi-shared/src/url/scheme.rs index 948f05a7..ccc86cdc 100644 --- a/yazi-shared/src/url/scheme.rs +++ b/yazi-shared/src/url/scheme.rs @@ -1,7 +1,7 @@ use std::{borrow::Cow, fmt::Display}; use anyhow::{Result, bail}; -use percent_encoding::{CONTROLS, PercentEncode, percent_decode, percent_encode}; +use percent_encoding::{AsciiSet, CONTROLS, PercentEncode, percent_decode, percent_encode}; use crate::{BytesExt, url::Loc}; @@ -73,7 +73,10 @@ impl Scheme { } #[inline] - fn encode_param<'a>(s: &'a str) -> PercentEncode<'a> { percent_encode(s.as_bytes(), CONTROLS) } + fn encode_param<'a>(s: &'a str) -> PercentEncode<'a> { + const SET: AsciiSet = CONTROLS.add(b'/'); + percent_encode(s.as_bytes(), &SET) + } pub fn encode_tilded(&self, loc: &Loc) -> String { let loc = percent_encode(loc.as_os_str().as_encoded_bytes(), CONTROLS);