From 1c9e417e7854c38e5722ce4ff6c7da2b04de3653 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 10:58:20 -1000 Subject: Cover how link-commits applies its rules Skipping a malformed rule, the tie between two rules, the scan past an empty match, a rule with no capture and the switch for object names were all untested, and none of the shipped examples beyond the issue rule had ever been loaded. --- tests/extensions/test-link-commits.lua | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests/extensions/test-link-commits.lua') diff --git a/tests/extensions/test-link-commits.lua b/tests/extensions/test-link-commits.lua index 45a3f60..fa3a040 100644 --- a/tests/extensions/test-link-commits.lua +++ b/tests/extensions/test-link-commits.lua @@ -85,4 +85,45 @@ h.load_with(script, { { "local rules = {", "local rules = { { pattern = \"T:(%S+ out = render("T:a'b%c") h.equals("a captured value is percent-encoded into the url", out, "T:a'b%c") +-- A malformed pattern is the operator's error, so that rule is skipped and +-- the others still run. +h.load_with(script, { { "local rules = {", "local rules = { { pattern = \"(%d+\", url = \"https://x/%s\" }," } }) +out = render("fixed 42 in deadbee") +h.equals("a malformed rule is skipped and object names still link", out, + "fixed 42 in deadbee") + +-- Two rules matching at the same place leave it to the one listed first. +h.load_with(script, { { "local rules = {", + "local rules = { { pattern = \"#(%d+)\", url = \"https://a/%s\" }, { pattern = \"#(%d%d)\", url = \"https://b/%s\" }," } }) +out = render("#12") +h.equals("the rule listed first wins a tie", out, "#12") + +-- A pattern that can match nothing still moves the scan on, or the page +-- would never finish. +h.load_with(script, { { "local rules = {", "local rules = { { pattern = \"x*\", url = \"https://x/%s\" }," } }) +out = render("abc") +h.equals("a rule matching the empty string still reaches the end", (out:gsub("<[^>]*>", "")), "abc") + +h.load_with(script, { { "local rules = {", "local rules = { { pattern = \"RFC%d+\", url = \"https://r/%s\" }," } }) +out = render("see RFC123") +h.equals("a rule with no capture puts the whole match in the url", out, "see RFC123") + +h.load_with(script, { { "enabled = true,", "enabled = false," } }) +out = render("fixed in deadbee") +h.equals("object names can be left unlinked", out, "fixed in deadbee") + +h.load_with(script, { + { "-- { pattern = \"CVE", "{ pattern = \"CVE" }, + { "-- url = \"https://www.cve.org", " url = \"https://www.cve.org" }, + { "-- { pattern = \"!", "{ pattern = \"!" }, + { "-- url = \"https://gitlab", " url = \"https://gitlab" }, + { "-- { pattern = \"RFC", "{ pattern = \"RFC" }, + { "-- url = \"https://www.rfc-editor", " url = \"https://www.rfc-editor" }, +}) +out = render("CVE-2024-12345, !42 and RFC 9110") +h.equals("the shipped examples link what they describe", out, + "CVE-2024-12345, " .. + "!42 and " .. + "RFC 9110") + h.finish() -- cgit 2.12.1