diff options
Diffstat (limited to 'custom/extensions/email-libravatar.lua')
-rw-r--r--custom/extensions/email-libravatar.lua16
1 file changed, 15 insertions, 1 deletion
diff --git a/custom/extensions/email-libravatar.lua b/custom/extensions/email-libravatar.lua
index 9b3d595..1fb979d 100644
--- a/custom/extensions/email-libravatar.lua
+++ b/custom/extensions/email-libravatar.lua
@@ -56,6 +56,20 @@ local function hash_hex(input)
return hex
end
+-- Lua patterns backtrack, so "^%s*(.-)%s*$" would cost the square of a long
+-- run of spaces inside the address. Finding each end directly stays linear.
+local function trim(text)
+ local first = text:find("%S")
+ if first == nil then
+ return ""
+ end
+ local last = #text
+ while text:find("^%s", last) do
+ last = last - 1
+ end
+ return text:sub(first, last)
+end
+
-- cgit can hand over the address still wrapped in angle brackets, and the
-- service hashes the trimmed lowercase form, so an address that skipped this
-- would hash to something the service has never heard of. A missing or empty
@@ -68,7 +82,7 @@ local function normalize_email(email)
if inner ~= nil then
email = inner
end
- email = (email:gsub("^%s*(.-)%s*$", "%1")):lower()
+ email = trim(email):lower()
if email == "" then
return nil
end