Changeset

116:f68a781efe81

mod_muc_log_http: support escaped urls
author Thilo Cestonaro <thilo@cestona.ro>
date Thu, 14 Jan 2010 12:54:44 +0100
parents 115:5e657a305c88
children 117:ecf05eb2d833
files mod_muc_log_http/muc_log_http/mod_muc_log_http.lua
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_muc_log_http/muc_log_http/mod_muc_log_http.lua	Mon Jan 04 14:20:48 2010 +0000
+++ b/mod_muc_log_http/muc_log_http/mod_muc_log_http.lua	Thu Jan 14 12:54:44 2010 +0100
@@ -8,6 +8,7 @@
 local tabSort = table.sort;
 local tonumber = _G.tonumber;
 local tostring = _G.tostring;
+local strchar = string.char;
 local strformat = string.format;
 local splitJid = require "util.jid".split;
 local config_get = require "core.configmanager".get;
@@ -71,10 +72,20 @@
 	end
 end
 
+function urlunescape (escapedUrl)
+	escapedUrl = escapedUrl:gsub("+", " ")
+	escapedUrl = escapedUrl:gsub("%%(%x%x)", function(h) return strchar(tonumber(h,16)) end)
+	escapedUrl = escapedUrl:gsub("\r\n", "\n")
+	return escapedUrl
+end
+
 local function htmlEscape(t)
 	t = t:gsub("<", "&lt;");
 	t = t:gsub(">", "&gt;");
-	t = t:gsub("(http://[%a%d@%.:/&%?=%-_#]+)", [[<a href="%1">%1</a>]]);
+	t = t:gsub("(http://[%a%d@%.:/&%?=%-_#%%]+)", function(h)
+		h = urlunescape(h)
+		return "<a href='" .. h .. "'>" .. h .. "</a>";
+	end);
 	t = t:gsub("\n", "<br />");
 	return t;
 end