fix: keep original scheme when expanding URLs (#3028)

This commit is contained in:
三咲雅 misaki masa 2025-07-30 02:08:17 +08:00 committed by GitHub
parent 9c1f303f2c
commit 9adc00c3a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 7 deletions

View file

@ -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::<Self>()?.inner.into_search(frag)))
methods.add_function_mut("into_search", |_, (ud, frag): (AnyUserData, mlua::String)| {
Ok(Self::new(ud.take::<Self>()?.inner.into_search(frag.to_str()?)))
});
methods.add_meta_method(MetaMethod::Eq, |_, me, other: UrlRef| Ok(me.inner == other.inner));

View file

@ -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<Path>) -> 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>>) -> 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 {

View file

@ -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);