comparison rust/hg-core/src/revlog/path_encode.rs @ 50331:0b84474ebd0a stable

rhg: fix a bug in path encoding, demonstrated in the parent commit
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Fri, 24 Mar 2023 19:02:46 +0000
parents eb07591825fa
children 3f5137543773
comparison
equal deleted inserted replaced
50330:eb07591825fa 50331:0b84474ebd0a
544 for slice in src[..last_slash].split(|b| *b == b'/') { 544 for slice in src[..last_slash].split(|b| *b == b'/') {
545 let slice = &slice[..std::cmp::min(slice.len(), dirprefixlen)]; 545 let slice = &slice[..std::cmp::min(slice.len(), dirprefixlen)];
546 if dest.len() + slice.len() > maxshortdirslen + 3 { 546 if dest.len() + slice.len() > maxshortdirslen + 3 {
547 break; 547 break;
548 } else { 548 } else {
549 dest.write_bytes(slice); 549 let last_char = slice[slice.len() - 1];
550 if last_char == b'.' || last_char == b' ' {
551 dest.write_bytes(&slice[0..slice.len() - 1]);
552 dest.write_byte(b'_');
553 } else {
554 dest.write_bytes(slice);
555 }
550 } 556 }
551 dest.write_byte(b'/'); 557 dest.write_byte(b'/');
552 } 558 }
553 } 559 }
554 560
610 use crate::utils::hg_path::HgPathBuf; 616 use crate::utils::hg_path::HgPathBuf;
611 617
612 #[test] 618 #[test]
613 fn test_dirname_ends_with_underscore() { 619 fn test_dirname_ends_with_underscore() {
614 let input = b"data/dir1234.foo/ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ.i"; 620 let input = b"data/dir1234.foo/ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ.i";
615 // TODO: BUG: trailing dot should become an underscore 621 let expected = b"dh/dir1234_/abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij.if2e9ce59e095eff5f8f334dc809e65606a0aa50b.i";
616 let expected = b"dh/dir1234./abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij.if2e9ce59e095eff5f8f334dc809e65606a0aa50b.i";
617 let res = path_encode(input); 622 let res = path_encode(input);
618 assert_eq!( 623 assert_eq!(
619 HgPathBuf::from_bytes(&res), 624 HgPathBuf::from_bytes(&res),
620 HgPathBuf::from_bytes(expected) 625 HgPathBuf::from_bytes(expected)
621 ); 626 );