Comparison

net/http.lua @ 4865:9171dc2357e0

net.http: Fix urlencode to not encode unreserved characters, so I can guiltlessly rant about people who do.
author Matthew Wild <mwild1@gmail.com>
date Sat, 12 May 2012 02:50:38 +0100
parent 4557:2abe4e541d52
child 4963:54e2c83af127
child 4972:1777271a1ec0
comparison
equal deleted inserted replaced
4864:b98154bbe0e0 4865:9171dc2357e0
66 request:reader(nil); 66 request:reader(nil);
67 end 67 end
68 requests[conn] = nil; 68 requests[conn] = nil;
69 end 69 end
70 70
71 function urlencode(s) return s and (s:gsub("%W", function (c) return format("%%%02x", c:byte()); end)); end 71 function urlencode(s) return s and (s:gsub("[^a-zA-Z0-9.~_-]", function (c) return format("%%%02x", c:byte()); end)); end
72 function urldecode(s) return s and (s:gsub("%%(%x%x)", function (c) return char(tonumber(c,16)); end)); end 72 function urldecode(s) return s and (s:gsub("%%(%x%x)", function (c) return char(tonumber(c,16)); end)); end
73 73
74 local function _formencodepart(s) 74 local function _formencodepart(s)
75 return s and (s:gsub("%W", function (c) 75 return s and (s:gsub("%W", function (c)
76 if c ~= " " then 76 if c ~= " " then