Skip to content

Commit 560daec

Browse files
committed
Fix hash prefix collision
For example `(UniCase::new("prefix"), UniCase::new("suffix"))` would always collide with (Unicase::new("pre"), Unicase::new("fixsuffix")). See also rust-lang/rust#5257.
1 parent 7b116bc commit 560daec

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/ascii.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ impl<S: AsRef<str>> Hash for Ascii<S> {
127127
for byte in self.as_ref().bytes().map(|b| b.to_ascii_lowercase()) {
128128
hasher.write_u8(byte);
129129
}
130+
hasher.write_u8(0xff);
130131
}
131132
}
132133

src/unicode/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ impl<S: AsRef<str>> Hash for Unicode<S> {
5959
let mut buf = [0; 4];
6060
for c in self.0.as_ref().chars().flat_map(|c| lookup(c)) {
6161
let len = char_to_utf8(c, &mut buf);
62-
hasher.write(&buf[..len])
62+
hasher.write(&buf[..len]);
6363
}
64+
hasher.write_u8(0xff);
6465
}
6566
}
6667

0 commit comments

Comments
 (0)