Skip to content

Commit efa6343

Browse files
committed
Include non-redundant separators in the hash for Path
1 parent 103806b commit efa6343

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Diff for: library/std/src/path.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -3109,17 +3109,25 @@ impl Hash for Path {
31093109
bytes_hashed += to_hash.len();
31103110
}
31113111

3112-
// skip over separator and optionally a following CurDir item
3112+
// Skip over separators and, optionally, a following CurDir item
31133113
// since components() would normalize these away.
31143114
component_start = i + 1;
31153115

31163116
let tail = &bytes[component_start..];
31173117

31183118
if !verbatim {
31193119
component_start += match tail {
3120+
[] => 0, // Do not hash a trailing separator
31203121
[b'.'] => 1,
31213122
[b'.', sep @ _, ..] if is_sep_byte(*sep) => 1,
3122-
_ => 0,
3123+
_ => {
3124+
// Hash the first separator so we can distinguish between
3125+
// `foo/bar` and `foobar`
3126+
let to_hash = &[b'/' as u8];
3127+
h.write(to_hash);
3128+
bytes_hashed += to_hash.len();
3129+
0
3130+
}
31233131
};
31243132
}
31253133
}

0 commit comments

Comments
 (0)