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 30f81c7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
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 30f81c7

Please sign in to comment.