From 032edc5d43b826af3338689c4cfaf15490be18e4 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 --- src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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('/')