Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Replace a readme's NUL bytes in one substitution
Diffstat (limited to '')
| -rw-r--r-- | custom/extensions/about-render.lua | 22 |
1 file changed, 3 insertions, 19 deletions
diff --git a/custom/extensions/about-render.lua b/custom/extensions/about-render.lua index c19846e..62da9a8 100644 --- a/custom/extensions/about-render.lua +++ b/custom/extensions/about-render.lua @@ -1018,26 +1018,10 @@ end -- cgit takes filter output through a C string sink that stops at the first -- 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 - +-- text past it survives. The class names NUL as the one byte outside \1 to +-- \255, since on Lua 5.1 a zero byte in a pattern ends it. function filter_close() - local text = replace_nul(table.concat(chunks)) + local text = table.concat(chunks):gsub("[^\1-\255]", "\239\191\189") chunks = {} local ext = (filename:match("%.([^.]+)$") or ""):lower() local render = #text <= max_bytes and handlers[ext] or render_plaintext |
