Skip to content

Commit

Permalink
Include non-redundant separators in the hash for Path
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Jul 3, 2024
1 parent 103806b commit efa6343
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3109,17 +3109,25 @@ impl Hash for Path {
bytes_hashed += to_hash.len();
}

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

let tail = &bytes[component_start..];

if !verbatim {
component_start += match tail {
[] => 0, // Do not hash a trailing separator
[b'.'] => 1,
[b'.', sep @ _, ..] if is_sep_byte(*sep) => 1,
_ => 0,
_ => {
// Hash the first separator so we can distinguish between
// `foo/bar` and `foobar`
let to_hash = &[b'/' as u8];
h.write(to_hash);
bytes_hashed += to_hash.len();
0
}
};
}
}
Expand Down

0 comments on commit efa6343

Please sign in to comment.