Răsfoiți Sursa

Add url encode to body (#40)

Chris Black 8 ani în urmă
părinte
comite
dac2d07b97
1 a modificat fișierele cu 10 adăugiri și 3 ștergeri
  1. 10 3
      sms/resources/install/scripts/app/sms/index.lua

+ 10 - 3
sms/resources/install/scripts/app/sms/index.lua

@@ -41,6 +41,13 @@
 		json = require "resources.functions.lunajson"
 		json = require "resources.functions.lunajson"
 	end
 	end
 
 
+local function urlencode(s)
+	s = string.gsub(s, "([^%w])",function(c)
+		return string.format("%%%02X", string.byte(c))
+	end)
+	return s
+end
+
 --define uuid function
 --define uuid function
 	local random = math.random;
 	local random = math.random;
 	local function uuid()
 	local function uuid()
@@ -63,7 +70,7 @@
 	if direction == "inbound" then
 	if direction == "inbound" then
 		to = argv[3];
 		to = argv[3];
 		from = argv[4];
 		from = argv[4];
-		body = argv[5];
+		body = urlencode(argv[5]);
 		domain_name = string.match(to,'%@+(.+)');
 		domain_name = string.match(to,'%@+(.+)');
 		extension = string.match(to,'%d+');
 		extension = string.match(to,'%d+');
 
 
@@ -121,9 +128,9 @@
 			from = message:getHeader("from_user");
 			from = message:getHeader("from_user");
 		end
 		end
 		if (argv[5] ~= nil) then
 		if (argv[5] ~= nil) then
-			body = argv[5];
+			body = urlencode(argv[5]);
 		else
 		else
-			body = message:getBody();
+			body = urlencode(message:getBody());
 		end
 		end
 
 
 		if (debug["info"]) then
 		if (debug["info"]) then