diff options
Diffstat (limited to '')
| -rw-r--r-- | custom/extensions/link-commits.lua | 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rw-r--r-- | custom/extensions/link-trailers.lua | 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rw-r--r-- | tests/extensions/test-link-commits.lua | 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rw-r--r-- | tests/extensions/test-link-trailers.lua | 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rwxr-xr-x | tests/t0503-link-commits.sh | 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rwxr-xr-x | tests/t0506-link-trailers.sh | 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6 files changed, 43 insertions, 24 deletions
diff --git a/custom/extensions/link-commits.lua b/custom/extensions/link-commits.lua index 8dc0bc3..31d2e3a 100644 --- a/custom/extensions/link-commits.lua +++ b/custom/extensions/link-commits.lua @@ -31,7 +31,9 @@ local objects = { -- URL where %s is replaced by that capture, percent-encoded. The whole match -- is what gets shown and the capture is only what goes into the URL. Rules are -- tried in order and the leftmost match wins, so put the more specific --- patterns first, and an empty list leaves only object names linked. +-- patterns first, and an empty list leaves only object names linked. The +-- examples are commented out, so an unedited copy links object names alone, +-- and the tracker one wants this site's own address before it goes in. -- -- Lua patterns are not regular expressions. The reference is -- https://www.lua.org/manual/5.1/manual.html#5.4.1 @@ -40,7 +42,7 @@ local objects = { -- '&', '<' and '>' rather than the bare characters, and keep a -- pattern from ending part way through one. local rules = { - { pattern = "#(%d+)", url = "https://bugs.example.com/?bug=%s" }, + -- { pattern = "#(%d+)", url = "https://bugs.example.com/?bug=%s" }, -- { pattern = "CVE%-(%d%d%d%d%-%d+)", -- url = "https://www.cve.org/CVERecord?id=CVE-%s" }, -- { pattern = "!(%d+)", diff --git a/custom/extensions/link-trailers.lua b/custom/extensions/link-trailers.lua index 645c517..d5be662 100644 --- a/custom/extensions/link-trailers.lua +++ b/custom/extensions/link-trailers.lua @@ -30,9 +30,10 @@ local rules = { -- current page and works for the common virtual-root layout. { key = "Fixes", pattern = "^(%x%x%x%x%x%x%x+)", url = "./?id=%s" }, { key = "Reverts", pattern = "^(%x%x%x%x%x%x%x+)", url = "./?id=%s" }, - -- Closes: #123 and Bug: 123 point at the tracker. - { key = "Closes", pattern = "^#?(%d+)$", url = "https://bugs.example.com/?bug=%s" }, - { key = "Bug", pattern = "^#?(%d+)$", url = "https://bugs.example.com/?bug=%s" }, + -- Closes: #123 and Bug: 123 can point at the tracker once its address + -- stands in for the example one. + -- { key = "Closes", pattern = "^#?(%d+)$", url = "https://bugs.example.com/?bug=%s" }, + -- { key = "Bug", pattern = "^#?(%d+)$", url = "https://bugs.example.com/?bug=%s" }, -- { key = "CVE", pattern = "^CVE%-(%d%d%d%d%-%d+)$", -- url = "https://www.cve.org/CVERecord?id=CVE-%s" }, } diff --git a/tests/extensions/test-link-commits.lua b/tests/extensions/test-link-commits.lua index 07b2fdb..fdd1787 100644 --- a/tests/extensions/test-link-commits.lua +++ b/tests/extensions/test-link-commits.lua @@ -1,7 +1,8 @@ -- Unit checks for custom/extensions/link-commits.lua, run under a standalone -- Lua by t0503-link-commits.sh with the script path as the argument. The --- shipped configuration links bare object names to ./?id= and issue marks --- like #123 to bugs.example.com, and everything here checks that shape, the +-- shipped configuration links bare object names to ./?id= and leaves issue +-- marks as text. The rest runs with the commented-out issue rule switched on, +-- linking marks like #123 to bugs.example.com, and checks that shape, the -- length bounds and frontier on hash recognition, and the rule that no run -- of text is ever wrapped twice. @@ -14,7 +15,13 @@ local function render(text) return h.run({}, { text }) end -local out, ret = render("see #123 for details") +local out, ret = render("see #123 near deadbee") +h.equals("an unedited copy leaves issue marks as text", out, + "see #123 near <a href='./?id=deadbee'>deadbee</a>") + +h.load_with(arg[1], { { "-- { pattern = \"#(%d+)\"", "{ pattern = \"#(%d+)\"" } }) + +out, ret = render("see #123 for details") h.contains("issue mark becomes a link", out, "<a href='https://bugs.example.com/?bug=123'>#123</a>") h.contains("text around the link survives", out, "see ") h.contains("text after the link survives", out, " for details") diff --git a/tests/extensions/test-link-trailers.lua b/tests/extensions/test-link-trailers.lua index c879340..7aed9d2 100644 --- a/tests/extensions/test-link-trailers.lua +++ b/tests/extensions/test-link-trailers.lua @@ -1,9 +1,10 @@ -- Unit checks for custom/extensions/link-trailers.lua, run under a standalone -- Lua by t0506-link-trailers.sh with the script path as the argument. The --- shipped configuration links Fixes and Reverts object names to ./?id=, --- Closes and Bug marks to bugs.example.com and a bare URL to itself, and --- everything here checks that shape, the key matching and the values that --- must pass through untouched. +-- shipped configuration links Fixes and Reverts object names to ./?id= and a +-- bare URL to itself, and leaves Closes and Bug marks as text. The rest runs +-- with the commented-out tracker rules switched on, linking those marks to +-- bugs.example.com, and checks that shape, the key matching and the values +-- that must pass through untouched. local test_directory = arg[0]:match("^(.*)/") or "." local h = dofile(test_directory .. "/harness.lua") @@ -14,6 +15,13 @@ local function render(key, text) return h.run({ key, "commit" }, { text }) end +h.equals("an unedited copy leaves a Closes mark as text", render("Closes", "#45"), "#45") + +h.load_with(arg[1], { + { "-- { key = \"Closes\"", "{ key = \"Closes\"" }, + { "-- { key = \"Bug\"", "{ key = \"Bug\"" }, +}) + local out, ret = render("Fixes", "1234567 (\"plain commit\")") h.contains("a Fixes object name links to its commit", out, "<a href='./?id=1234567'>1234567</a> (\"plain commit\")") diff --git a/tests/t0503-link-commits.sh b/tests/t0503-link-commits.sh index d977517..fc7d618 100755 --- a/tests/t0503-link-commits.sh +++ b/tests/t0503-link-commits.sh @@ -1,10 +1,10 @@ #!/bin/sh # Checks link-commits.lua, the shipped commit-filter, whose configuration as -# shipped links bare object names to ./?id= and issue marks like #123 to -# bugs.example.com. The unit checks cover the matching rules under every -# suitable standalone Lua, and a commit whose message carries one of each is -# then rendered through cgit itself. +# shipped links bare object names to ./?id= and leaves issue marks like #123 +# as text until a tracker is set up. The unit checks cover the matching rules +# under every suitable standalone Lua, and a commit whose message carries one +# of each is then rendered through cgit itself. test_description='Check the shipped link-commits extension' CGIT_TEST_NO_CREATE_REPOS=YesPlease @@ -46,9 +46,10 @@ test_expect_success 'point cgit at it through the commit filter' ' EOF ' -test_expect_success CGIT_LUA 'the issue mark links out on the commit page' ' +test_expect_success CGIT_LUA 'the issue mark stays text on the commit page' ' cgit_url "linky/commit/" >tmp && - grep "bugs.example.com/?bug=123.>#123</a>" tmp + grep "fix #123 near" tmp && + ! grep "bugs.example.com" tmp ' test_expect_success CGIT_LUA 'the object name links to its own page' ' diff --git a/tests/t0506-link-trailers.sh b/tests/t0506-link-trailers.sh index 7ce9f53..39e22e7 100755 --- a/tests/t0506-link-trailers.sh +++ b/tests/t0506-link-trailers.sh @@ -1,10 +1,10 @@ #!/bin/sh # Checks link-trailers.lua, the shipped trailer-filter, whose configuration as -# shipped links Fixes and Reverts object names to ./?id=, Closes and Bug marks -# to bugs.example.com and a bare URL to itself. The unit checks cover the rules -# under every suitable standalone Lua, and a commit carrying one of each is -# then rendered through cgit itself. +# shipped links Fixes and Reverts object names to ./?id= and a bare URL to +# itself, and leaves Closes and Bug marks as text until a tracker is set up. +# The unit checks cover the rules under every suitable standalone Lua, and a +# commit carrying one of each is then rendered through cgit itself. test_description='Check the shipped link-trailers extension' CGIT_TEST_NO_CREATE_REPOS=YesPlease @@ -62,8 +62,8 @@ test_expect_success CGIT_LUA 'the bare URL links to itself' ' grep "<a href=.https://example.com/?a=1&b=2.>https://example.com/?a=1&b=2</a>" tmp ' -test_expect_success CGIT_LUA 'the Closes mark links out' ' - grep "bugs.example.com/?bug=45.>#45</a>" tmp +test_expect_success CGIT_LUA 'the Closes mark stays text' ' + grep "<th scope=.row.>Closes</th><td>#45</td>" tmp ' test_done |
