mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix: keep original scheme when expanding URLs (#3028)
This commit is contained in:
parent
9c1f303f2c
commit
9adc00c3a9
3 changed files with 11 additions and 7 deletions
|
|
@ -157,8 +157,8 @@ impl UserData for Url {
|
||||||
Ok(url.map(Self::new))
|
Ok(url.map(Self::new))
|
||||||
});
|
});
|
||||||
|
|
||||||
methods.add_function_mut("into_search", |_, (ud, frag): (AnyUserData, String)| {
|
methods.add_function_mut("into_search", |_, (ud, frag): (AnyUserData, mlua::String)| {
|
||||||
Ok(Self::new(ud.take::<Self>()?.inner.into_search(frag)))
|
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));
|
methods.add_meta_method(MetaMethod::Eq, |_, me, other: UrlRef| Ok(me.inner == other.inner));
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use std::{borrow::Cow, env, ffi::{OsStr, OsString}, future::Future, io, path::{Path, PathBuf}};
|
use std::{borrow::Cow, env, ffi::{OsStr, OsString}, future::Future, io, path::{Path, PathBuf}};
|
||||||
|
|
||||||
use anyhow::{Result, bail};
|
use anyhow::{Result, bail};
|
||||||
use yazi_shared::url::Url;
|
use yazi_shared::url::{Loc, Url};
|
||||||
|
|
||||||
use crate::{CWD, services};
|
use crate::{CWD, services};
|
||||||
|
|
||||||
|
|
@ -35,11 +35,12 @@ fn _clean_path(path: &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()) }
|
||||||
|
|
||||||
// FIXME: keep the original scheme of the Url
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn expand_url<'a>(url: impl Into<Cow<'a, Url>>) -> Cow<'a, Url> {
|
pub fn expand_url<'a>(url: impl Into<Cow<'a, Url>>) -> Cow<'a, Url> {
|
||||||
let u: Cow<'a, Url> = url.into();
|
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 {
|
fn _expand_path(p: &Path) -> PathBuf {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use std::{borrow::Cow, fmt::Display};
|
use std::{borrow::Cow, fmt::Display};
|
||||||
|
|
||||||
use anyhow::{Result, bail};
|
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};
|
use crate::{BytesExt, url::Loc};
|
||||||
|
|
||||||
|
|
@ -73,7 +73,10 @@ impl Scheme {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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 {
|
pub fn encode_tilded(&self, loc: &Loc) -> String {
|
||||||
let loc = percent_encode(loc.as_os_str().as_encoded_bytes(), CONTROLS);
|
let loc = percent_encode(loc.as_os_str().as_encoded_bytes(), CONTROLS);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue