Mercurial > hg
changeset 50332:3f5137543773 stable
rhg: don't crash on empty directory names in path_encode, just in case
I don't expect that to be possible, but there's nothing in path_encode.rs
that prevents it, and the old code didn't crash in this case, so it's
better to be defensive.
author | Arseniy Alekseyev <aalekseyev@janestreet.com> |
---|---|
date | Fri, 24 Mar 2023 19:19:37 +0000 |
parents | 0b84474ebd0a |
children | 80784ac09460 |
files | rust/hg-core/src/revlog/path_encode.rs |
diffstat | 1 files changed, 4 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/path_encode.rs Fri Mar 24 19:02:46 2023 +0000 +++ b/rust/hg-core/src/revlog/path_encode.rs Fri Mar 24 19:19:37 2023 +0000 @@ -545,15 +545,15 @@ let slice = &slice[..std::cmp::min(slice.len(), dirprefixlen)]; if dest.len() + slice.len() > maxshortdirslen + 3 { break; - } else { - let last_char = slice[slice.len() - 1]; - if last_char == b'.' || last_char == b' ' { + } + if let Some(last_char) = slice.last() { + if *last_char == b'.' || *last_char == b' ' { dest.write_bytes(&slice[0..slice.len() - 1]); dest.write_byte(b'_'); } else { dest.write_bytes(slice); } - } + }; dest.write_byte(b'/'); } }