# HG changeset patch # User Arseniy Alekseyev # Date 1676559274 0 # Node ID 362fe34702d542c3f130ec5f5131db400f778620 # Parent 1cffc156f7cd30ead125118f46a7eecc01e0a63f rhg: demonstrate a bug in path_encode The bug means that long filenames at the root of the tree are encoded incorrectly by rhg, so rhg crashes when trying to access them. diff -r 1cffc156f7cd -r 362fe34702d5 rust/hg-core/src/revlog/path_encode.rs --- a/rust/hg-core/src/revlog/path_encode.rs Thu Feb 16 14:43:46 2023 +0000 +++ b/rust/hg-core/src/revlog/path_encode.rs Thu Feb 16 14:54:34 2023 +0000 @@ -643,3 +643,22 @@ hash_encode(path) } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::utils::hg_path::HgPathBuf; + + // expected failure + #[test] + #[should_panic] + fn test_long_filename_at_root() { + let input = b"data/ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ.i"; + let expected = b"dh/abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij.i708243a2237a7afae259ea3545a72a2ef11c247b.i"; + let res = path_encode(input); + assert_eq!( + HgPathBuf::from_bytes(&res), + HgPathBuf::from_bytes(expected) + ); + } +}