Comparison

mod_pastebin/mod_pastebin.lua @ 501:e851f386c904

mod_pastebin: Threshold is now UTF-8 characters (thanks Grom_PE for initial patch)
author Matthew Wild <mwild1@gmail.com>
date Thu, 08 Dec 2011 22:01:54 +0000
parent 454:3f101f7a26d0
child 512:c819365ac6ab
comparison
equal deleted inserted replaced
500:bd08727378be 501:e851f386c904
15 or (start >= 240 and start <= 244 and #seq < 4) 15 or (start >= 240 and start <= 244 and #seq < 4)
16 or (start > 244) then 16 or (start > 244) then
17 return ""; 17 return "";
18 end 18 end
19 return seq; 19 return seq;
20 end
21
22 local function utf8_length(str)
23 local _, count = string.gsub(str, "[^\128-\193]", "");
24 return count;
20 end 25 end
21 26
22 local pastebin_private_messages = module:get_option_boolean("pastebin_private_messages", hosts[module.host].type ~= "component"); 27 local pastebin_private_messages = module:get_option_boolean("pastebin_private_messages", hosts[module.host].type ~= "component");
23 local length_threshold = module:get_option_number("pastebin_threshold", 500); 28 local length_threshold = module:get_option_number("pastebin_threshold", 500);
24 local line_threshold = module:get_option_number("pastebin_line_threshold", 4); 29 local line_threshold = module:get_option_number("pastebin_line_threshold", 4);
76 body = body:get_text(); 81 body = body:get_text();
77 82
78 --module:log("debug", "Body(%s) length: %d", type(body), #(body or "")); 83 --module:log("debug", "Body(%s) length: %d", type(body), #(body or ""));
79 84
80 if body and ( 85 if body and (
81 (#body > length_threshold) or 86 ((#body > length_threshold)
87 and (length_utf8(body) > length_threshold)) or
82 (trigger_string and body:find(trigger_string, 1, true) == 1) or 88 (trigger_string and body:find(trigger_string, 1, true) == 1) or
83 (select(2, body:gsub("\n", "%0")) >= line_threshold) 89 (select(2, body:gsub("\n", "%0")) >= line_threshold)
84 ) then 90 ) then
85 if trigger_string then 91 if trigger_string then
86 body = body:gsub("^" .. trigger_string, "", 1); 92 body = body:gsub("^" .. trigger_string, "", 1);