From 6583af9ae6ee8adf9cd810b39fd15a32c10953d2 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 10:30:19 -1000 Subject: Check the log line for lexers that are not found Every check set CGIT_SCINTILLUA_PATH, which the filter takes as given, so the line for a server with no Scintillua at all never ran and deleting it passed. The harness can now clear a variable and hide the directories the filter probes. A lexer.lua anywhere on LUA_PATH also loaded in place of the missing one, so the fallback runs now keep every Lua module out of reach. --- tests/extensions/test-syntax-highlight.lua | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'tests/extensions/test-syntax-highlight.lua') diff --git a/tests/extensions/test-syntax-highlight.lua b/tests/extensions/test-syntax-highlight.lua index 08cc72d..d8e5224 100644 --- a/tests/extensions/test-syntax-highlight.lua +++ b/tests/extensions/test-syntax-highlight.lua @@ -4,8 +4,10 @@ -- life of the interpreter, so the two sides of that split are two runs of -- this file. In highlight mode the shell points CGIT_SCINTILLUA_PATH at the -- fake-lexers directory beside this file and every path through a working --- lexer is checked, and in nolexers mode it points at an empty directory so --- the escaped fallback is what everything renders through. +-- lexer is checked. In nolexers mode it points at an empty directory, so +-- the escaped fallback is what everything renders through, and the run ends +-- with every directory the filter probes hidden, for a server with no +-- Scintillua at all. local test_directory = arg[0]:match("^(.*)/") or "." local h = dofile(test_directory .. "/harness.lua") @@ -21,10 +23,10 @@ end if mode == "nolexers" then local out, ret = render("hello.fake", "if 42") - h.equals("without lexers source is served escaped", out, "if 42") + h.equals("without lexers the source passes through uncoloured", out, "if 42") h.equals("close answers zero", ret, 0) - h.contains("and the error log says the lexers would not load", h.error_log(), - "Unable to load the Scintillua lexers") + h.equals("and the error log says the lexers would not load", h.error_log(), + "[cgit] Unable to load the Scintillua lexers: module 'lexer' not found:\n") out = render("hello.fake", "a & c") h.equals("the fallback escapes markup", out, "a <b> & c") @@ -47,6 +49,23 @@ if mode == "nolexers" then h.equals("a separator across a slice boundary is still escaped", out, string.rep("x", 64 * 1024 - 1) .. "\\u2028y") + -- With the variable unset and no lexers beside cgitrc or in any directory + -- the filter probes, it finds nothing to load, the usual case on a server + -- without Scintillua. + local file = assert(io.open(script, "rb")) + local source = file:read("*a") + file:close() + for dir in source:match("local scintillua_dirs = (%b{})"):gmatch('"([^"]+)"') do + h.redirect_file(dir .. "/lexer.lua", "/nonexistent/lexer.lua") + end + h.setenv("CGIT_SCINTILLUA_PATH", nil) + h.setenv("CGIT_CONFIG", nil) + h.load(script) + out = render("hello.fake", "a ") + h.equals("with no lexers found the source is served escaped", out, "a <b>") + h.equals("and the error log says none were found", h.error_log(), + "[cgit] Unable to find the Scintillua lexers, so source is shown uncoloured\n") + h.finish() end -- cgit 2.12.1