From 30f81c7c1b51eab7befee4b220549090b6d0560b Mon Sep 17 00:00:00 2001 From: Thomas Tanon Date: Sat, 21 Dec 2024 19:17:25 +0100 Subject: [PATCH] Relativize: avoid panic in case of shared UTF-8 prefix --- Cargo.toml | 1 - src/lib.rs | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 69b40e8..403bfa4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,6 @@ serde = { version = "1.0.166", optional = true } [dev-dependencies] codspeed-criterion-compat = "2.3.3" serde_test = "1" -clap = "4" [[bench]] name = "lib" diff --git a/src/lib.rs b/src/lib.rs index 9ac2a54..ca00060 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -703,10 +703,11 @@ impl> Iri { } if abs_path != base_path || abs_query.is_none() && base_query.is_some() { let number_of_shared_characters = abs_path - .bytes() - .zip(base_path.bytes()) + .chars() + .zip(base_path.chars()) .take_while(|(l, r)| l == r) - .count(); + .map(|(l, _)| l.len_utf8()) + .sum::(); // We decrease until finding a / let number_of_shared_characters = abs_path[..number_of_shared_characters] .rfind('/')