[core] Share paths: invisible characters (default-ignorable code points, combining marks) do not hide a dot-only segment

This commit is contained in:
2026-11-07 19:57:06 +01:00
parent 443d7457d2
commit 7863202e3a
2 changed files with 57 additions and 3 deletions
+38 -3
View File
@@ -412,6 +412,30 @@ const SLASH_LOOKALIKES: &[char] = &[
'\u{2215}', '\u{2044}', '\u{29F8}', '\u{29F9}', '\u{2216}', '\u{29F5}', '\u{2571}', '\u{2572}',
];
/// Unicode's Default_Ignorable_Code_Point (DerivedCoreProperties.txt, Unicode 15).
fn default_ignorable(c: char) -> bool {
matches!(
c as u32,
0x00AD
| 0x034F
| 0x061C
| 0x115F..=0x1160
| 0x17B4..=0x17B5
| 0x180B..=0x180F
| 0x200B..=0x200F
| 0x202A..=0x202E
| 0x2060..=0x206F
| 0x3164
| 0xFE00..=0xFE0F
| 0xFEFF
| 0xFFA0
| 0xFFF0..=0xFFF8
| 0x1BCA0..=0x1BCA3
| 0x1D173..=0x1D17A
| 0xE0000..=0xE0FFF
)
}
/// Decode `%xx` escapes once. `None` for a broken escape.
fn percent_decode(raw: &str) -> Option<Vec<u8>> {
let b = raw.as_bytes();
@@ -444,7 +468,8 @@ fn percent_decode(raw: &str) -> Option<Vec<u8>> {
/// - any encoded character that NFKC normalisation turns into something containing `/`, `\`,
/// `;`, `?`, `#`, `%` or a control character (fullwidth and small forms), and the slash
/// look-alikes NFKC leaves alone ([`SLASH_LOOKALIKES`]);
/// - a segment that NFKC turns into only dots or nothing, after trimming whitespace (two-dot
/// - a segment that NFKC turns into only dots or nothing, after dropping default-ignorable
/// characters and combining marks and trimming whitespace (two-dot
/// leaders, ellipses, fullwidth dots, look-alike spaces); look-alike dots and spaces inside a
/// name with other characters (`Wait….pdf`, an ideographic space) are fine;
/// - a segment of only dots, also with `;params` (`..;x`, `..%3b`), and any segment that is
@@ -493,9 +518,19 @@ pub fn path_within(prefix: &str, raw_path: &str) -> bool {
if seg.is_ascii() {
continue; // the raw checks below cover ASCII segments
}
// Invisible characters (default-ignorable code points, combining marks) do not count:
// `\u{200B}..` is `..` to a server that drops them.
let n: String = seg.nfkc().collect();
let name = n.split(';').next().unwrap_or("").trim();
if name.chars().all(|c| c == '.') {
let visible: String = n
.split(';')
.next()
.unwrap_or("")
.chars()
.filter(|c| {
!default_ignorable(*c) && !unicode_normalization::char::is_combining_mark(*c)
})
.collect();
if visible.trim().chars().all(|c| c == '.') {
return false;
}
}