diff options
Diffstat (limited to 'custom/extensions/email-gravatar.lua')
| -rw-r--r-- | custom/extensions/email-gravatar.lua | 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 15 insertions, 1 deletion
diff --git a/custom/extensions/email-gravatar.lua b/custom/extensions/email-gravatar.lua index 6eb5376..01db3f9 100644 --- a/custom/extensions/email-gravatar.lua +++ b/custom/extensions/email-gravatar.lua @@ -58,6 +58,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 @@ -70,7 +84,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 |
