[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: luasocket escaping patch.
- From: "Adam D. Moss" <adam@...>
- Date: Thu, 11 Nov 2004 17:21:38 +0000
Hi!
This patch does two simple things:
1) url.escape() no longer escapes characters that don't have to
be escaped. That makes its results more readable and thus
immensely more debuggable.
2) url.unescape()'s comments described url.escape().
--Adam
--
Adam D. Moss . ,,^^ adam@gimp.org http://www.foxbox.org/ co:3
Index: url.lua
===================================================================
--- url.lua (revision 2999)
+++ url.lua (working copy)
@@ -13,7 +13,7 @@
-- escaped representation of string binary
-----------------------------------------------------------------------------
function escape(s)
- return string.gsub(s, "(.)", function(c)
+ return string.gsub(s, "([^A-Za-z0-9_])", function(c)
return string.format("%%%02x", string.byte(c))
end)
end
@@ -49,11 +49,11 @@
end
-----------------------------------------------------------------------------
--- Encodes a string into its escaped hexadecimal representation
+-- Decodes a string from its escaped hexadecimal representation
-- Input
--- s: binary string to be encoded
+-- s: encoded string to be decoded
-- Returns
--- escaped representation of string binary
+-- unescaped binary string
-----------------------------------------------------------------------------
function unescape(s)
return string.gsub(s, "%%(%x%x)", function(hex)