From 37079696b0d73e55f51d2de7dca7c1ff19273d3c Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Thu, 29 Oct 2026 14:37:25 -1000 Subject: Keep a readme whole past a NUL byte cgit takes filter output through a C string sink that stops at the first NUL, so a readme holding one lost everything after it. Each NUL now shows as U+FFFD, as a browser would show it. --- custom/extensions/about-render.lua | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'custom/extensions/about-render.lua') diff --git a/custom/extensions/about-render.lua b/custom/extensions/about-render.lua index 1e59716..d7753a3 100644 --- a/custom/extensions/about-render.lua +++ b/custom/extensions/about-render.lua @@ -820,9 +820,27 @@ function filter_write(str) end -- cgit takes filter output through a C string sink that stops at the first --- NUL byte, so a write holding one loses everything from the NUL on. +-- NUL byte, so each one becomes U+FFFD, as a browser would show it, and the +-- text past it survives. A plain find works on Lua 5.1, where a NUL cannot +-- sit in a pattern. +local function replace_nul(text) + if not text:find("\0", 1, true) then + return text + end + local parts, start = {}, 1 + while true do + local at = text:find("\0", start, true) + if not at then + parts[#parts + 1] = text:sub(start) + return table.concat(parts, "\239\191\189") + end + parts[#parts + 1] = text:sub(start, at - 1) + start = at + 1 + end +end + function filter_close() - local text = table.concat(chunks) + local text = replace_nul(table.concat(chunks)) chunks = {} local ext = (filename:match("%.([^.]+)$") or ""):lower() local render = handlers[ext] or render_plaintext -- cgit