index : gitrs
A lightweight web interface for browsing Git repositories, implemented in Rust
about summary refs log tree commit diff

Diffstat (limited to 'src/main.rs')

-rw-r--r-- src/main.rs 27
 1 file changed, 27 insertions(+)

diff --git a/src/main.rs b/src/main.rs
index ef61bfd..9913e79 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -102,4 +102,31 @@
        assert!(!commits[0].branch_tips(&repo).unwrap().is_empty());
        assert!(start.elapsed().as_millis() < 100);
    }

    #[test]
    fn resolve_path_supports_explicit_commit_id() {
        let repo = Repository::open(Path::new(env!("CARGO_MANIFEST_DIR"))).unwrap();
        let current_ref = Ref {
            name: repo.head_branch_name().unwrap(),
            is_head: true,
        };
        let gix_repo = repo.gix();
        let (commits, _) = repo.commits(&gix_repo, &current_ref, 0, 2, None).unwrap();
        let oldest = commits.last().unwrap();

        let view = repo
            .resolve_path(&current_ref, Some(&oldest.id), "Cargo.toml")
            .unwrap();
        assert!(matches!(view, crate::git::tree::PathView::Blob(_)));
    }

    #[test]
    fn markdown_escapes_attribute_injections_in_media() {
        let md = "![demo & test](https://github.com/user-attachments/assets/1234?a=1&b=2)";
        let html = markdown::render(md, "git-rs", "main");
        assert!(html.contains(r#"alt="demo &amp; test""#));
        assert!(
            html.contains(r#"src="https://github.com/user-attachments/assets/1234?a=1&amp;b=2""#)
        );
    }
}