From b927386173b179d124815e366989da07a711ab3e Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 24 Oct 2026 09:17:41 -1000 Subject: Show characters a browser breaks at as escapes The HTML parser turns a carriage return with no line feed after it into a line feed, and WebKit starts a new line at U+2028 and U+2029, while git and the line numbers count line feeds alone, so each one set every later line of the tree and blame pages a line below its number. CSS Text makes vertical tab, form feed and next line forced breaks as well, though no engine honours that yet. The escapes follow gitweb, which shows control characters the same way. --- tests/t0104-tree.sh | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'tests/t0104-tree.sh') diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh index fefff4a..d464f8c 100755 --- a/tests/t0104-tree.sh +++ b/tests/t0104-tree.sh @@ -31,6 +31,57 @@ test_expect_success 'the code is set in the font of its line numbers' ' grep "^ font: inherit;$" rule ' +# A browser starts a new line at more characters than git ends one at, and +# each would push the rest of the code a line below its numbers. +test_expect_success 'set up a file holding the characters a browser breaks at' ' + test_create_repo repos/breaks && + ( + cd repos/breaks && + printf "a\\rb\\vc\\fd\\302\\205e\\342\\200\\250f\\342\\200\\251g\\nh\\r\\ni\\r" >breaks.txt && + git add breaks.txt && + git commit -m breaks + ) && + { + echo "virtual-root=/" && + echo "cache-size=0" && + echo "enable-blame=1" && + echo "repo.url=breaks" && + echo "repo.path=$PWD/repos/breaks/.git" + } >breaksrc +' + +test_expect_success 'each of them is shown as an escape in the tree' ' + CGIT_CONFIG="$PWD/breaksrc" QUERY_STRING="url=breaks/tree/breaks.txt" cgit >tmp && + grep "a\\\\rb\\\\vc" tmp && + grep "c\\\\fd\\\\u0085e" tmp && + grep "e\\\\u2028f\\\\u2029g$" tmp +' + +test_expect_success 'only a carriage return before a line feed is left as it is' ' + printf "h\\r\\n" >expect && + grep "^h" tmp >actual && + test_cmp expect actual && + grep "^i\\\\r" tmp +' + +test_expect_success 'the numbers count only the lines git counts' ' + grep "3" tmp && + ! grep "4" tmp +' + +test_expect_success 'the blame page escapes them the same way' ' + CGIT_CONFIG="$PWD/breaksrc" QUERY_STRING="url=breaks/blame/breaks.txt" cgit >tmp && + grep "a\\\\rb\\\\vc" tmp && + grep "e\\\\u2028f\\\\u2029g$" tmp && + grep "^i\\\\r" tmp +' + +# The striped background is padded with spaces to the widest line, which is +# 31 columns once its six escapes are written out, though it is 18 bytes. +test_expect_success 'the blame stripes are as wide as the escaped line' ' + grep "^ \\{31\\}" tmp +' + test_expect_success 'generate foo+bar/tree' 'cgit_url "foo%2bbar/tree" >tmp' test_expect_success 'verify a+b link' ' -- cgit 2.9.1