Changeset

1268:854a3933cfcd

mod_muc_log_http: URL-encode room names. This allows special characters in room names to work. Ideally this escaping shouldn’t be done in the user visible content, but the module’s template system doesn’t currently allow that.
author Waqas Hussain <waqas20@gmail.com>
date Sat, 04 Jan 2014 16:50:57 -0500
parents 1267:589991b148e8
children 1269:69d42d2427f7
files mod_muc_log_http/muc_log_http/mod_muc_log_http.lua
diffstat 1 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mod_muc_log_http/muc_log_http/mod_muc_log_http.lua	Sat Jan 04 20:34:22 2014 +0100
+++ b/mod_muc_log_http/muc_log_http/mod_muc_log_http.lua	Sat Jan 04 16:50:57 2014 -0500
@@ -62,6 +62,9 @@
 	url = url:gsub("\r\n", "\n")
 	return url
 end
+local function urlencode(s)
+	return s and (s:gsub("[^a-zA-Z0-9.~_-]", function (c) return ("%%%02x"):format(c:byte()); end));
+end
 
 local function generate_room_list(component)
 	local rooms = "";
@@ -70,7 +73,7 @@
 		for jid, room in pairs(component_host.muc.rooms) do
 			local node = split_jid(jid);
 			if not room._data.hidden and room._data.logging and node then
-				rooms = rooms .. html.rooms.bit:gsub("###ROOM###", node):gsub("###COMPONENT###", component);
+				rooms = rooms .. html.rooms.bit:gsub("###ROOM###", urlencode(node)):gsub("###COMPONENT###", component);
 			end
 		end
 		return html.rooms.body:gsub("###ROOMS_STUFF###", rooms):gsub("###COMPONENT###", component), "Chatroom logs for "..component;
@@ -242,7 +245,7 @@
 					found = 1
 				end
 
-				rooms = rooms .. html.days.rooms.bit:gsub("###ROOM###", node);
+				rooms = rooms .. html.days.rooms.bit:gsub("###ROOM###", urlencode(node));
 			end
 		end