diff options
Diffstat (limited to '')
-rw-r--r--tests/extensions/test-syntax-highlight.lua29
-rwxr-xr-xtests/t0005-markup.sh23
-rwxr-xr-xtests/t0104-tree.sh60
-rwxr-xr-xtests/t0109-patch.sh10
-rwxr-xr-xtests/t0502-syntax-highlight.sh11
5 files changed, 126 insertions, 7 deletions
diff --git a/tests/extensions/test-syntax-highlight.lua b/tests/extensions/test-syntax-highlight.lua
index a87cd80..f831b01 100644
--- a/tests/extensions/test-syntax-highlight.lua
+++ b/tests/extensions/test-syntax-highlight.lua
@@ -33,6 +33,17 @@ if mode == "nolexers" then
out = render("big.fake", string.rep("x<y>", 30000))
h.equals("slicing loses nothing at the boundaries", out, string.rep("x&lt;y&gt;", 30000))
+ out = render("hello.fake", "a\rb\vc\fd\r\ne")
+ h.equals("the fallback escapes what a browser breaks at", out,
+ "a<span class='escape'>\\r</span>b<span class='escape'>\\v</span>c" ..
+ "<span class='escape'>\\f</span>d\ne")
+
+ -- The line separator starts on the last byte of the first slice, and
+ -- its other two bytes would land in the next one.
+ out = render("big.fake", string.rep("x", 64 * 1024 - 1) .. "\226\128\168y")
+ h.equals("a separator across a slice boundary is still escaped", out,
+ string.rep("x", 64 * 1024 - 1) .. "<span class='escape'>\\u2028</span>y")
+
h.finish()
end
@@ -70,6 +81,24 @@ h.equals("an extension with no lexer serves escaped text", out, "import &lt;x&gt
out = render("noextension", "words <here>")
h.equals("a file with no extension serves escaped text", out, "words &lt;here&gt;")
+-- The line numbers beside the code count line feeds alone, so each character
+-- a browser would start a line at is an escape, and CR LF reaches the page as
+-- the line feed a browser would have made of it.
+out = render("hello.fake", "if\r42\vzz\f'a'\r\nif")
+h.equals("what a browser breaks at is escaped between tokens", out,
+ "<span class='hl-keyword'>if</span><span class='escape'>\\r</span>" ..
+ "<span class='hl-number'>42</span><span class='escape'>\\v</span>" ..
+ "<span class='hl-keyword'>zz</span><span class='escape'>\\f</span>" ..
+ "<span class='hl-string'>'a'</span>\n<span class='hl-keyword'>if</span>")
+
+-- The fake lexer hands back every byte of a separator as a token of its own.
+out = render("hello.fake", "a\194\133b\226\128\168c\226\128\169d")
+h.equals("a separator split between tokens is escaped whole", out,
+ "<span class='hl-keyword'>a</span><span class='escape'>\\u0085</span>" ..
+ "<span class='hl-keyword'>b</span><span class='escape'>\\u2028</span>" ..
+ "<span class='hl-keyword'>c</span><span class='escape'>\\u2029</span>" ..
+ "<span class='hl-keyword'>d</span>")
+
out = render("big.fake", string.rep("a", 512 * 1024 + 1))
h.excludes("an oversized blob skips the lexing pass", out, "<span")
h.equals("and still arrives whole", #out, 512 * 1024 + 1)
diff --git a/tests/t0005-markup.sh b/tests/t0005-markup.sh
index e3cb08d..5d802a7 100755
--- a/tests/t0005-markup.sh
+++ b/tests/t0005-markup.sh
@@ -90,21 +90,31 @@ test_expect_success 'the blob, blame and about pages open with their own contain
grep "<div id=.about.>" tmp
'
+# A browser gives these elements a monospace font of its own, which would
+# otherwise win over the one a theme sets through --font-mono.
+test_expect_success 'every monospace element takes the theme font' '
+ sed -n "/^div#cgit code,$/,/^}/p" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.css" >rule &&
+ grep "^div#cgit pre,$" rule &&
+ grep "^ font-family: var(--font-mono);$" rule
+'
+
test_expect_success 'the stylesheet and the script name only the current hooks' '
! grep "_dark\|#summary\|ul.pager\|td:empty" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.css" &&
grep "window.cgit.updateAges" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.js" &&
grep "window.cgit.highlightLines" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.js"
'
-# The rest of the hooks need a tag, a symlink, a submodule, a trailer, clone
-# urls, an empty repository and a second page of repositories, so they get a
-# commit and a config of their own after the checks above have read the first
-# ones.
+# The rest of the hooks need a tag, a symlink, a submodule, a trailer, a lone
+# carriage return, clone urls, an empty repository and a second page of
+# repositories, so they get a commit and a config of their own after the checks
+# above have read the first ones.
test_expect_success 'set up the remaining kinds of entry' '
(
cd repos/hooks &&
git tag -a -m "first release" v1 &&
test_ln_s_add file-1 link &&
+ printf "a\\rb\\n" >cr.txt &&
+ git add cr.txt &&
git update-index --add --cacheinfo "160000,$(git rev-parse HEAD),sub" &&
git commit -m "more kinds of entry" -m "Fixes: $(git rev-parse --short HEAD)"
) &&
@@ -139,6 +149,11 @@ test_expect_success 'the refs, summary and tree name every section and row' '
grep "<tr class=.mod.>" tmp
'
+test_expect_success 'a character the browser would break a line at is an escape' '
+ more "hooks/tree/cr.txt" >tmp &&
+ grep "a<span class=.escape.>" tmp
+'
+
test_expect_success 'the commit page has its trailer table and diffstat' '
more "hooks/commit/" >tmp &&
grep "<table class=.commit-trailers.>" tmp &&
diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh
index b48c394..d464f8c 100755
--- a/tests/t0104-tree.sh
+++ b/tests/t0104-tree.sh
@@ -22,6 +22,66 @@ test_expect_success 'no line 2' '
! grep "<a id=.n2. href=.#n2.>2</a>" tmp
'
+# The numbers and the code are two columns of text that a browser keeps in
+# step only while both are set in one font. Only a browser shows the drift,
+# so this checks the rule that prevents it.
+test_expect_success 'the code is set in the font of its line numbers' '
+ sed -n "/^div#cgit table.blob code {/,/^}/p" \
+ "$TEST_OUTPUT_DIRECTORY/../assets/cgit.css" >rule &&
+ 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 "<code>a<span class=.escape.>\\\\r</span>b<span class=.escape.>\\\\v</span>c" tmp &&
+ grep "c<span class=.escape.>\\\\f</span>d<span class=.escape.>\\\\u0085</span>e" tmp &&
+ grep "e<span class=.escape.>\\\\u2028</span>f<span class=.escape.>\\\\u2029</span>g$" 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<span class=.escape.>\\\\r</span></code>" tmp
+'
+
+test_expect_success 'the numbers count only the lines git counts' '
+ grep "<a id=.n3. href=.#n3.>3</a>" tmp &&
+ ! grep "<a id=.n4. href=.#n4.>4</a>" 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 "<code>a<span class=.escape.>\\\\r</span>b<span class=.escape.>\\\\v</span>c" tmp &&
+ grep "e<span class=.escape.>\\\\u2028</span>f<span class=.escape.>\\\\u2029</span>g$" tmp &&
+ grep "^i<span class=.escape.>\\\\r</span></code>" 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\\}</pre></div>" tmp
+'
+
test_expect_success 'generate foo+bar/tree' 'cgit_url "foo%2bbar/tree" >tmp'
test_expect_success 'verify a+b link' '
diff --git a/tests/t0109-patch.sh b/tests/t0109-patch.sh
index 3cb9d08..0c4bf8c 100755
--- a/tests/t0109-patch.sh
+++ b/tests/t0109-patch.sh
@@ -8,9 +8,13 @@
test_description='Check content on patch page'
. ./setup.sh
+# The version the built binary signs its patches with, without the v of the
+# tag, as git writes its own.
+CGIT_VERSION=$(sed -n "s/CGIT_VERSION = v\{0,1\}//p" "$TEST_OUTPUT_DIRECTORY/../build/VERSION")
+
# The signature sits on the second-to-last line, above the trailing blank.
check_cgit_signature() {
- tail -2 tmp | head -1 | grep "^cgit$"
+ tail -2 tmp | head -1 | grep -x -F "cgit $CGIT_VERSION"
}
test_expect_success 'generate foo/patch' '
@@ -35,7 +39,7 @@ test_expect_success 'find `cgit` signature' '
test_expect_success 'compare with output of git-format-patch(1)' '
git --git-dir="$PWD/repos/foo/.git" format-patch --subject-prefix="" \
- --signature="cgit" --stdout HEAD^ >tmp2 &&
+ --signature="cgit $CGIT_VERSION" --stdout HEAD^ >tmp2 &&
strip_headers <tmp >tmp_ &&
test_cmp tmp_ tmp2
'
@@ -64,7 +68,7 @@ test_expect_success 'find `cgit` signature on the range' '
test_expect_success 'compare the range with git-format-patch(1)' '
git --git-dir="$PWD/repos/foo/.git" format-patch --subject-prefix="" \
- -N --signature="cgit" --stdout HEAD~3..HEAD >tmp2 &&
+ -N --signature="cgit $CGIT_VERSION" --stdout HEAD~3..HEAD >tmp2 &&
strip_headers <tmp >tmp_ &&
test_cmp tmp_ tmp2
'
diff --git a/tests/t0502-syntax-highlight.sh b/tests/t0502-syntax-highlight.sh
index 31ab7e7..ced9edd 100755
--- a/tests/t0502-syntax-highlight.sh
+++ b/tests/t0502-syntax-highlight.sh
@@ -70,4 +70,15 @@ test_expect_success CGIT_LUA 'bytes between tokens reach the page escaped' '
grep "<span class=.hl-number.>42</span> &amp; " tmp
'
+test_expect_success CGIT_LUA 'a lone carriage return reaches the page as an escape' '
+ (
+ cd repos/fake &&
+ printf "if\\rzz\\n" >cr.fake &&
+ git add cr.fake &&
+ git commit -m "add a lone carriage return"
+ ) &&
+ cgit_url "fake/tree/cr.fake" >tmp &&
+ grep "<span class=.hl-keyword.>if</span><span class=.escape.>\\\\r</span>" tmp
+'
+
test_done