Skip to content

Commit

Permalink
Relativize: avoid panic in case of shared UTF-8 prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Tpt committed Dec 21, 2024
1 parent 8305079 commit 1f5ac7b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,10 +703,11 @@ impl<T: Deref<Target = str>> Iri<T> {
}
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::<usize>();
// We decrease until finding a /
let number_of_shared_characters = abs_path[..number_of_shared_characters]
.rfind('/')
Expand Down

0 comments on commit 1f5ac7b

Please sign in to comment.