Diff options
| -rw-r--r-- | source/ui-tree.c | 4 | |
| -rwxr-xr-x | tests/t0104-tree.sh | 23 |
2 files changed, 27 insertions, 0 deletions
diff --git a/source/ui-tree.c b/source/ui-tree.c index b682f3e..f89498a 100644 --- a/source/ui-tree.c +++ b/source/ui-tree.c @@ -270,6 +270,10 @@ static void print_dir_chain(const struct object_id *oid, const char *name, /* * Whether git counts the blob as binary, read through a stream so that only * the bytes buffer_is_binary looks at are inflated, however large the blob. + * The blame page and the file view also count a NUL anywhere in the blob, so + * a file whose first NUL lies past this window is still offered a blame link + * that leads to "Blob is binary". Finding that NUL would mean inflating the + * whole of every blob the listing names. */ static bool blob_starts_binary(const struct object_id *oid) { diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh index d2f5234..5fdc6ac 100755 --- a/tests/t0104-tree.sh +++ b/tests/t0104-tree.sh @@ -318,4 +318,27 @@ test_expect_success 'a listing offers blame only where it works' ' ! grep "href=./bin/blame/big.bin.>blame</a>" tmp ' +# The listing sniffs only the window git judges binary by, while blame and +# the file view look for a NUL anywhere, so a file whose NUL lies past that +# window is offered a blame link that ends on the binary notice. Reading the +# whole of every blob would cost more than that link does. +test_expect_success 'a NUL past the first 8000 bytes still gets a blame link' ' + test_create_repo repos/late && + ( + cd repos/late && + test_seq 1 2000 >late.txt && + printf "\\000end\\n" >>late.txt && + git add late.txt && + git commit -m "late NUL" + ) && + cgitrc_repo laterc late enable-blame=1 && + cgit_ok laterc "url=late/tree/" >tmp && + test_grep "href=./late/blame/late.txt.>blame</a>" tmp && + cgit_ok laterc "url=late/blame/late.txt" >tmp && + test_grep "<div class=.error.>Blob is binary</div>" tmp && + cgit_ok laterc "url=late/tree/late.txt" >tmp && + test_grep "<table class=.bin-blob. tabindex=.0. aria-label=.Hex dump.>" tmp && + test_grep ! ">blame</a>" tmp +' + test_done |
