Skip to content

Commit 3561867

Browse files
committed
feat: WTF-8 validator (#3374)
1 parent 329c80c commit 3561867

File tree

26 files changed

+311
-169
lines changed

26 files changed

+311
-169
lines changed

Cargo.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

yazi-actor/src/mgr/refresh.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ impl Refresh {
4848

4949
// TODO: performance improvement
5050
fn trigger_dirs(folders: &[&Folder]) {
51-
async fn go(cwd: UrlBuf, cha: Cha) {
52-
let Some(cha) = Files::assert_stale(&cwd, cha).await else { return };
51+
async fn go(dir: UrlBuf, cha: Cha) {
52+
let Some(cha) = Files::assert_stale(&dir, cha).await else { return };
5353

54-
match Files::from_dir_bulk(&cwd).await {
55-
Ok(files) => FilesOp::Full(cwd, files, cha).emit(),
56-
Err(e) => FilesOp::issue_error(&cwd, e).await,
54+
match Files::from_dir_bulk(&dir).await {
55+
Ok(files) => FilesOp::Full(dir, files, cha).emit(),
56+
Err(e) => FilesOp::issue_error(&dir, e).await,
5757
}
5858
}
5959

yazi-boot/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ clap = { workspace = true }
2121
futures = { workspace = true }
2222
hashbrown = { workspace = true }
2323
regex = { workspace = true }
24-
serde = { workspace = true }
2524

2625
[build-dependencies]
2726
yazi-shared = { path = "../yazi-shared", version = "25.9.15" }

yazi-fm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ tokio-stream = { workspace = true }
5959

6060
# Logging
6161
tracing = { workspace = true }
62-
tracing-appender = "0.2.3"
62+
tracing-appender = "0.2.4"
6363
tracing-subscriber = { version = "0.3.20", features = [ "env-filter" ] }
6464

6565
[target."cfg(unix)".dependencies]

yazi-fs/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ scopeguard = { workspace = true }
3232
serde = { workspace = true }
3333
tokio = { workspace = true }
3434
tracing = { workspace = true }
35+
typed-path = { workspace = true }
3536

3637
[target."cfg(unix)".dependencies]
3738
libc = { workspace = true }

yazi-fs/src/path/expand.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{borrow::Cow, path::PathBuf};
22

3-
use yazi_shared::{FromWtf8Vec, loc::LocBuf, path::{PathBufDyn, PathCow, PathDyn, PathKind, PathLike}, pool::InternStr, url::{AsUrl, Url, UrlBuf, UrlCow, UrlLike}};
3+
use yazi_shared::{loc::LocBuf, path::{PathBufDyn, PathCow, PathDyn, PathKind, PathLike}, pool::InternStr, url::{AsUrl, Url, UrlBuf, UrlCow, UrlLike}, wtf8::FromWtf8Vec};
44

55
use crate::{CWD, path::clean_url};
66

@@ -25,21 +25,25 @@ fn expand_url_impl<'a>(url: Url<'a>) -> UrlCow<'a> {
2525
let mut path = PathBufDyn::with_capacity(url.kind(), n_base.len() + n_rest.len() + n_urn.len());
2626
path.try_extend([n_base, n_rest, n_urn]).expect("extend original parts should not fail");
2727

28-
let loc = LocBuf::<PathBuf>::with(
29-
path.into_os().expect("Failed to convert PathBufDyn to PathBuf"),
30-
(uri_count + rest_diff + urn_diff) as usize,
31-
(urn_count + urn_diff) as usize,
32-
)
33-
.expect("Failed to create Loc from expanded path");
28+
let uri = (uri_count + rest_diff + urn_diff) as usize;
29+
let urn = (urn_count + urn_diff) as usize;
3430

3531
let expanded = match url {
36-
Url::Regular(_) => UrlBuf::Regular(loc),
37-
Url::Search { domain, .. } => UrlBuf::Search { loc, domain: domain.intern() },
38-
Url::Archive { domain, .. } => UrlBuf::Archive { loc, domain: domain.intern() },
39-
Url::Sftp { domain, .. } => {
40-
todo!();
41-
// UrlBuf::Sftp { loc, domain: domain.intern() }
42-
}
32+
Url::Regular(_) => UrlBuf::Regular(
33+
LocBuf::<std::path::PathBuf>::with(path.into_os().unwrap(), uri, urn).unwrap(),
34+
),
35+
Url::Search { domain, .. } => UrlBuf::Search {
36+
loc: LocBuf::<std::path::PathBuf>::with(path.into_os().unwrap(), uri, urn).unwrap(),
37+
domain: domain.intern(),
38+
},
39+
Url::Archive { domain, .. } => UrlBuf::Archive {
40+
loc: LocBuf::<std::path::PathBuf>::with(path.into_os().unwrap(), uri, urn).unwrap(),
41+
domain: domain.intern(),
42+
},
43+
Url::Sftp { domain, .. } => UrlBuf::Sftp {
44+
loc: LocBuf::<typed_path::UnixPathBuf>::with(path.into_unix().unwrap(), uri, urn).unwrap(),
45+
domain: domain.intern(),
46+
},
4347
};
4448

4549
absolute_url(expanded)

yazi-fs/src/path/percent.rs

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,32 @@
11
use std::{borrow::Cow, path::{Path, PathBuf}};
22

3+
use anyhow::Result;
34
use percent_encoding::{AsciiSet, CONTROLS, percent_decode, percent_encode};
4-
use yazi_shared::path::PathDyn;
5+
use yazi_shared::path::{PathCow, PathDyn, PathKind};
56

67
const SET: &AsciiSet =
78
&CONTROLS.add(b'"').add(b'*').add(b':').add(b'<').add(b'>').add(b'?').add(b'\\').add(b'|');
89

9-
pub trait PercentEncoding {
10-
fn percent_encode(&self) -> Cow<'_, Path>;
10+
pub trait PercentEncoding<'a> {
11+
fn percent_encode(self) -> Cow<'a, Path>;
1112

12-
fn percent_decode(&self) -> Cow<'_, [u8]>;
13+
fn percent_decode<K>(self, kind: K) -> Result<PathCow<'a>>
14+
where
15+
K: Into<PathKind>;
1316
}
1417

15-
impl PercentEncoding for Path {
16-
fn percent_encode(&self) -> Cow<'_, Path> {
17-
match percent_encode(self.as_os_str().as_encoded_bytes(), SET).into() {
18-
Cow::Borrowed(_) => self.into(),
18+
impl<'a> PercentEncoding<'a> for PathDyn<'a> {
19+
fn percent_encode(self) -> Cow<'a, Path> {
20+
match percent_encode(self.encoded_bytes(), SET).into() {
21+
Cow::Borrowed(s) => Path::new(s).into(),
1922
Cow::Owned(s) => PathBuf::from(s).into(),
2023
}
2124
}
2225

23-
fn percent_decode(&self) -> Cow<'_, [u8]> {
24-
match percent_decode(self.as_os_str().as_encoded_bytes()).into() {
25-
Cow::Borrowed(_) => self.as_os_str().as_encoded_bytes().into(),
26-
Cow::Owned(s) => s.into(),
27-
}
28-
}
29-
}
30-
31-
impl PercentEncoding for PathDyn<'_> {
32-
fn percent_encode(&self) -> Cow<'_, Path> {
33-
match self {
34-
PathDyn::Os(p) => p.percent_encode(),
35-
PathDyn::Unix(_) => todo!(),
36-
}
37-
}
38-
39-
fn percent_decode(&self) -> Cow<'_, [u8]> {
40-
match self {
41-
PathDyn::Os(p) => p.percent_decode(),
42-
PathDyn::Unix(_) => todo!(),
43-
}
26+
fn percent_decode<K>(self, kind: K) -> Result<PathCow<'a>>
27+
where
28+
K: Into<PathKind>,
29+
{
30+
PathCow::with(kind, percent_decode(self.encoded_bytes()))
4431
}
4532
}

yazi-fs/src/url.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::{borrow::Cow, ffi::OsStr, path::{Path, PathBuf}};
22

3-
use yazi_shared::{path::PathDyn, url::{AsUrl, Url, UrlBuf, UrlCow}};
3+
use yazi_shared::{path::{AsPath, PathDyn}, url::{AsUrl, Url, UrlBuf, UrlCow}};
44

5-
use crate::{FsHash128, FsScheme};
5+
use crate::{FsHash128, FsScheme, path::PercentEncoding};
66

77
pub trait FsUrl<'a> {
88
fn cache(&self) -> Option<PathBuf>;
@@ -26,13 +26,12 @@ impl<'a> FsUrl<'a> for Url<'a> {
2626
fn cache(&self) -> Option<PathBuf> {
2727
fn with_loc(loc: PathDyn, mut root: PathBuf) -> PathBuf {
2828
let mut it = loc.components();
29-
todo!();
30-
// if it.next() == Some(std::path::Component::RootDir) {
31-
// root.push(it.as_path().percent_encode());
32-
// } else {
33-
// root.push(".%2F");
34-
// root.push(loc.percent_encode());
35-
// }
29+
if it.next() == Some(yazi_shared::path::Component::RootDir) {
30+
root.push(it.as_path().percent_encode());
31+
} else {
32+
root.push(".%2F");
33+
root.push(loc.percent_encode());
34+
}
3635
root
3736
}
3837

yazi-plugin/src/process/command.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{any::TypeId, ffi::OsStr, io, process::Stdio};
33
use mlua::{AnyUserData, ExternalError, IntoLuaMulti, Lua, MetaMethod, Table, UserData, Value};
44
use tokio::process::{ChildStderr, ChildStdin, ChildStdout};
55
use yazi_binding::Error;
6-
use yazi_shared::FromWtf8;
6+
use yazi_shared::wtf8::FromWtf8;
77

88
use super::{Child, output::Output};
99
use crate::process::Status;

yazi-shared/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![allow(clippy::option_map_unit_fn)]
22

3-
yazi_macro::mod_pub!(data errors event loc path pool scheme shell strand translit url);
3+
yazi_macro::mod_pub!(data errors event loc path pool scheme shell strand translit url wtf8);
44

5-
yazi_macro::mod_flat!(alias bytes chars condition debounce either env id layer natsort os predictor ro_cell source sync_cell terminal tests throttle time utf8 wtf8);
5+
yazi_macro::mod_flat!(alias bytes chars condition debounce either env id layer natsort os predictor ro_cell source sync_cell terminal tests throttle time utf8);
66

77
pub fn init() {
88
pool::init();

0 commit comments

Comments
 (0)