Diff options
Diffstat (limited to 'custom/extensions')
| -rw-r--r-- | custom/extensions/about-render.lua | 22 |
1 file changed, 20 insertions, 2 deletions
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 |
