rhg: don't crash on empty directory names in path_encode, just in case stable
authorArseniy Alekseyev <aalekseyev@janestreet.com>
Fri, 24 Mar 2023 19:19:37 +0000
branchstable
changeset 50332 3f5137543773
parent 50331 0b84474ebd0a
child 50333 80784ac09460
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.
rust/hg-core/src/revlog/path_encode.rs
--- 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'/');
         }
     }