diff options
context:
space:
mode:
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Clean up the whole tree
Diffstat (limited to '')
-rw-r--r--custom/extensions/about-render.lua27
-rw-r--r--custom/extensions/auth-file.lua33
-rw-r--r--custom/extensions/auth-inline.lua33
-rw-r--r--custom/extensions/link-commits.lua15
-rw-r--r--custom/extensions/syntax-highlight.lua6
5 files changed, 38 insertions, 76 deletions
diff --git a/custom/extensions/about-render.lua b/custom/extensions/about-render.lua
index f4e7685..805265e 100644
--- a/custom/extensions/about-render.lua
+++ b/custom/extensions/about-render.lua
@@ -259,20 +259,17 @@ if has_lpeg then
local lang_char = R("az", "AZ", "09") + S("_.+#-")
local heading_line = C(P("#") * P("#") ^ -5) * space ^ 1 * C(P(1) ^ 0)
local function thematic(mark)
- return space ^ 0 * P(mark) * (space ^ 0 * P(mark)) ^ 2
- * space ^ 0 * eol
+ return space ^ 0 * P(mark) * (space ^ 0 * P(mark)) ^ 2 * space ^ 0 * eol
end
local break_line = thematic("-") + thematic("*") + thematic("_")
- local fence_line = space ^ 0 * (C(P("`") ^ 3) + C(P("~") ^ 3))
- * space ^ 0 * C(lang_char ^ 0)
+ local fence_line = space ^ 0 * (C(P("`") ^ 3) + C(P("~") ^ 3)) * space ^ 0 * C(lang_char ^ 0)
local close_backtick = space ^ 0 * P("`") ^ 3 * space ^ 0 * eol
local close_tilde = space ^ 0 * P("~") ^ 3 * space ^ 0 * eol
local quote_line = space ^ 0 * P(">")
local bullet = S("-*+")
local number = R("09") ^ 1 * S(".)")
local item_line = space ^ 0 * C(bullet + number) * space ^ 1 * C(P(1) ^ 0)
- local dash_cell = space ^ 0 * P(":") ^ -1 * P("-") ^ 1 * P(":") ^ -1
- * space ^ 0
+ local dash_cell = space ^ 0 * P(":") ^ -1 * P("-") ^ 1 * P(":") ^ -1 * space ^ 0
-- A delimiter row is dash-cells joined by pipes. Require at least one
-- pipe, a leading one or one between cells, so a bare rule of dashes
-- stays a thematic break and an ordinary paragraph line is never taken
@@ -299,8 +296,7 @@ if has_lpeg then
if line:match("^%s*$") then
i = i + 1
elseif fence then
- local close = (fence:sub(1, 1) == "`")
- and close_backtick or close_tilde
+ local close = (fence:sub(1, 1) == "`") and close_backtick or close_tilde
local code = {}
i = i + 1
while i <= n and not close:match(lines[i]) do
@@ -345,16 +341,14 @@ if has_lpeg then
lines = paragraph,
}
end
- elseif i + 1 <= n and line:find("|", 1, true)
- and table_delimiter:match(lines[i + 1]) then
+ elseif i + 1 <= n and line:find("|", 1, true) and table_delimiter:match(lines[i + 1]) then
local head = {}
for _, cell in ipairs(split_cells(line)) do
head[#head + 1] = parse_inline(cell)
end
local rows = {}
i = i + 2
- while i <= n and lines[i]:find("|", 1, true)
- and not lines[i]:match("^%s*$") do
+ while i <= n and lines[i]:find("|", 1, true) and not lines[i]:match("^%s*$") do
local row = {}
for _, cell in ipairs(split_cells(lines[i])) do
row[#row + 1] = parse_inline(cell)
@@ -386,8 +380,7 @@ if has_lpeg then
else
local paragraph = { parse_inline(line) }
i = i + 1
- while i <= n and not lines[i]:match("^%s*$")
- and not block_start:match(lines[i]) do
+ while i <= n and not lines[i]:match("^%s*$") and not block_start:match(lines[i]) do
paragraph[#paragraph + 1] = parse_inline(lines[i])
i = i + 1
end
@@ -416,8 +409,7 @@ if has_lpeg then
-- Roff fonts are a current state carried across a run rather than
-- opened and closed, so the inline pass tokenises to a flat list
-- and folds it into the nodes markdown emits, instead of nesting.
- local macro_line = S(".'") * space ^ 0 * C((1 - space) ^ 1)
- * space ^ 0 * C(P(1) ^ 0)
+ local macro_line = S(".'") * space ^ 0 * C((1 - space) ^ 1) * space ^ 0 * C(P(1) ^ 0)
local one_font = { B = "B", I = "I" }
local two_font = { CB = "B", BI = "B", CI = "I" }
@@ -535,8 +527,7 @@ if has_lpeg then
flush_paragraph(); nofill = true; nofill_lines = {}
elseif macro == "fi" then
flush_nofill()
- elseif macro == "B" or macro == "BR" or macro == "RB"
- or macro == "BI" or macro == "IB" then
+ elseif macro == "B" or macro == "BR" or macro == "RB" or macro == "BI" or macro == "IB" then
add_line({ { kind = "strong", kids = man_inline(rest) } })
elseif macro == "I" or macro == "IR" or macro == "RI" then
add_line({ { kind = "em", kids = man_inline(rest) } })
diff --git a/custom/extensions/auth-file.lua b/custom/extensions/auth-file.lua
index cd0f338..230aa6d 100644
--- a/custom/extensions/auth-file.lua
+++ b/custom/extensions/auth-file.lua
@@ -242,21 +242,18 @@ function get_secret()
-- created readable by anyone but the user cgit runs as, and
-- the old mask goes back on every way out.
local old_umask = sysstat.umask(63)
- local temporary_filename = secret_filename .. ".tmp." ..
- tohex(rand.bytes(16))
+ local temporary_filename = secret_filename .. ".tmp." .. tohex(rand.bytes(16))
local temporary_file = io.open(temporary_filename, "w")
if temporary_file == nil then
sysstat.umask(old_umask)
- error("cgit auth: cannot create secret file " ..
- secret_filename)
+ error("cgit auth: cannot create secret file " .. secret_filename)
end
local wrote = temporary_file:write(tohex(rand.bytes(32)))
local closed = temporary_file:close()
if not wrote or not closed then
os.remove(temporary_filename)
sysstat.umask(old_umask)
- error("cgit auth: failed writing secret file " ..
- secret_filename)
+ error("cgit auth: failed writing secret file " .. secret_filename)
end
-- The link is meant to fail when another worker won the race,
-- which leaves that worker's secret in place rather than
@@ -273,8 +270,7 @@ function get_secret()
secret_file:close()
if secret == nil or secret:len() ~= 64 then
secret = nil
- error("cgit auth: secret file " .. secret_filename ..
- " is malformed, expected 64 hex characters")
+ error("cgit auth: secret file " .. secret_filename .. " is malformed, expected 64 hex characters")
end
return secret
end
@@ -334,10 +330,8 @@ function validate_value(expected_field, cookie)
return nil
end
- local payload = field .. "|" .. value .. "|" ..
- tostring(expiration) .. "|" .. salt
- local expected_signature =
- tohex(hmac.new(get_secret(), "sha256"):final(payload))
+ local payload = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt
+ local expected_signature = tohex(hmac.new(get_secret(), "sha256"):final(payload))
if not constant_equals(signature, expected_signature) then
return nil
end
@@ -370,8 +364,7 @@ function secure_value(field, value, expiration)
local salt = tohex(rand.bytes(16))
value = url_encode(value)
field = url_encode(field)
- local payload = field .. "|" .. value .. "|" ..
- tostring(expiration) .. "|" .. salt
+ local payload = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt
local signature = tohex(hmac.new(get_secret(), "sha256"):final(payload))
return payload .. "|" .. signature
end
@@ -406,11 +399,9 @@ function set_cookie(cookie, value)
if value == "" then
attributes = attributes .. "; Max-Age=0"
elseif session_seconds > 0 then
- attributes = attributes ..
- "; Max-Age=" .. tostring(session_seconds)
+ attributes = attributes .. "; Max-Age=" .. tostring(session_seconds)
end
- html("Set-Cookie: " .. cookie .. "=" ..
- strip_controls(value) .. attributes .. "\n")
+ html("Set-Cookie: " .. cookie .. "=" .. strip_controls(value) .. attributes .. "\n")
end
function redirect_to(url)
@@ -454,8 +445,7 @@ function authenticate_post()
end
if ok then
- set_cookie(cookie_name, secure_value("username", username,
- os.time() + session_seconds))
+ set_cookie(cookie_name, secure_value("username", username, os.time() + session_seconds))
else
set_cookie(cookie_name, "")
end
@@ -473,8 +463,7 @@ function authenticate_cookie()
return 1
end
- local username = validate_value("username",
- get_cookie(http["cookie"], cookie_name))
+ local username = validate_value("username", get_cookie(http["cookie"], cookie_name))
if username == nil or not accepted_users[username:lower()] then
return 0
end
diff --git a/custom/extensions/auth-inline.lua b/custom/extensions/auth-inline.lua
index e26fa57..0ae2cb8 100644
--- a/custom/extensions/auth-inline.lua
+++ b/custom/extensions/auth-inline.lua
@@ -203,21 +203,18 @@ function get_secret()
-- created readable by anyone but the user cgit runs as, and
-- the old mask goes back on every way out.
local old_umask = sysstat.umask(63)
- local temporary_filename = secret_filename .. ".tmp." ..
- tohex(rand.bytes(16))
+ local temporary_filename = secret_filename .. ".tmp." .. tohex(rand.bytes(16))
local temporary_file = io.open(temporary_filename, "w")
if temporary_file == nil then
sysstat.umask(old_umask)
- error("cgit auth: cannot create secret file " ..
- secret_filename)
+ error("cgit auth: cannot create secret file " .. secret_filename)
end
local wrote = temporary_file:write(tohex(rand.bytes(32)))
local closed = temporary_file:close()
if not wrote or not closed then
os.remove(temporary_filename)
sysstat.umask(old_umask)
- error("cgit auth: failed writing secret file " ..
- secret_filename)
+ error("cgit auth: failed writing secret file " .. secret_filename)
end
-- The link is meant to fail when another worker won the race,
-- which leaves that worker's secret in place rather than
@@ -234,8 +231,7 @@ function get_secret()
secret_file:close()
if secret == nil or secret:len() ~= 64 then
secret = nil
- error("cgit auth: secret file " .. secret_filename ..
- " is malformed, expected 64 hex characters")
+ error("cgit auth: secret file " .. secret_filename .. " is malformed, expected 64 hex characters")
end
return secret
end
@@ -295,10 +291,8 @@ function validate_value(expected_field, cookie)
return nil
end
- local payload = field .. "|" .. value .. "|" ..
- tostring(expiration) .. "|" .. salt
- local expected_signature =
- tohex(hmac.new(get_secret(), "sha256"):final(payload))
+ local payload = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt
+ local expected_signature = tohex(hmac.new(get_secret(), "sha256"):final(payload))
if not constant_equals(signature, expected_signature) then
return nil
end
@@ -331,8 +325,7 @@ function secure_value(field, value, expiration)
local salt = tohex(rand.bytes(16))
value = url_encode(value)
field = url_encode(field)
- local payload = field .. "|" .. value .. "|" ..
- tostring(expiration) .. "|" .. salt
+ local payload = field .. "|" .. value .. "|" .. tostring(expiration) .. "|" .. salt
local signature = tohex(hmac.new(get_secret(), "sha256"):final(payload))
return payload .. "|" .. signature
end
@@ -367,11 +360,9 @@ function set_cookie(cookie, value)
if value == "" then
attributes = attributes .. "; Max-Age=0"
elseif session_seconds > 0 then
- attributes = attributes ..
- "; Max-Age=" .. tostring(session_seconds)
+ attributes = attributes .. "; Max-Age=" .. tostring(session_seconds)
end
- html("Set-Cookie: " .. cookie .. "=" ..
- strip_controls(value) .. attributes .. "\n")
+ html("Set-Cookie: " .. cookie .. "=" .. strip_controls(value) .. attributes .. "\n")
end
function redirect_to(url)
@@ -415,8 +406,7 @@ function authenticate_post()
end
if ok then
- set_cookie(cookie_name, secure_value("username", username,
- os.time() + session_seconds))
+ set_cookie(cookie_name, secure_value("username", username, os.time() + session_seconds))
else
set_cookie(cookie_name, "")
end
@@ -434,8 +424,7 @@ function authenticate_cookie()
return 1
end
- local username = validate_value("username",
- get_cookie(http["cookie"], cookie_name))
+ local username = validate_value("username", get_cookie(http["cookie"], cookie_name))
if username == nil or not accepted_users[username:lower()] then
return 0
end
diff --git a/custom/extensions/link-commits.lua b/custom/extensions/link-commits.lua
index 42252f3..8dc0bc3 100644
--- a/custom/extensions/link-commits.lua
+++ b/custom/extensions/link-commits.lua
@@ -81,8 +81,7 @@ local function collect(text)
pcall(function()
local init = 1
while init <= #text do
- local start, stop, capture =
- string.find(text, rule.pattern, init)
+ local start, stop, capture = string.find(text, rule.pattern, init)
if not start then break end
if capture == nil then
capture = string.sub(text, start, stop)
@@ -91,8 +90,7 @@ local function collect(text)
start = start,
stop = stop,
priority = priority,
- link = make_link(rule.url, capture,
- string.sub(text, start, stop)),
+ link = make_link(rule.url, capture, string.sub(text, start, stop)),
}
-- An empty match still has to advance the
-- scan, or it never reaches the end.
@@ -104,11 +102,9 @@ local function collect(text)
local priority = #rules + 1
local init = 1
while init <= #text do
- local start, stop, run =
- string.find(text, "%f[%w](%x+)%f[%W]", init)
+ local start, stop, run = string.find(text, "%f[%w](%x+)%f[%W]", init)
if not start then break end
- if #run >= objects.min_length
- and #run <= objects.max_length then
+ if #run >= objects.min_length and #run <= objects.max_length then
candidates[#candidates + 1] = {
start = start,
stop = stop,
@@ -145,8 +141,7 @@ function filter_close()
-- A candidate reaching back into one already emitted is
-- dropped, so no run of text is ever wrapped twice.
if candidate.start >= pos then
- out[#out + 1] =
- string.sub(text, pos, candidate.start - 1)
+ out[#out + 1] = string.sub(text, pos, candidate.start - 1)
out[#out + 1] = candidate.link
pos = candidate.stop + 1
end
diff --git a/custom/extensions/syntax-highlight.lua b/custom/extensions/syntax-highlight.lua
index e2032aa..2bff263 100644
--- a/custom/extensions/syntax-highlight.lua
+++ b/custom/extensions/syntax-highlight.lua
@@ -111,8 +111,7 @@ local function scintillua_path()
if config then
local dir = string.match(config, "^(.*)/[^/]+$")
if dir then
- candidates[#candidates + 1] =
- dir .. "/scintillua/lexers"
+ candidates[#candidates + 1] = dir .. "/scintillua/lexers"
end
end
for _, dir in ipairs(scintillua_dirs) do
@@ -201,8 +200,7 @@ local function highlight(text)
local part = escape(string.sub(text, pos, stop - 1))
local class = css[string.match(tag, "^[%w_]+")]
if class and part ~= "" then
- part = "<span class='" .. class .. "'>"
- .. part .. "</span>"
+ part = "<span class='" .. class .. "'>" .. part .. "</span>"
end
out[#out + 1] = part
pos = stop