Skip to content

Commit cc5e1f6

Browse files
migolovanov0x501D
authored andcommitted
uri_escape default configuration
Enable unescape_plus_sign for GET-parameters by default
1 parent 89f6edc commit cc5e1f6

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

http/server.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ local function query_param(self, name)
186186
local params = lib.params(self.query)
187187
local pres = {}
188188
for k, v in pairs(params) do
189-
pres[ uri_unescape(k) ] = uri_unescape(v)
189+
pres[ uri_unescape(k, true) ] = uri_unescape(v, true)
190190
end
191191
rawset(self, 'query_params', pres)
192192
end

test/integration/http_server_requests_test.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,33 @@ g.test_GET_and_POST = function()
160160
t.assert_equals(r.body, 'POST = test', 'POST reply')
161161
end
162162

163+
-- test GET parameters.
164+
g.test_GET_params = function()
165+
local httpd = g.httpd
166+
167+
local r = httpd:route({
168+
method = 'GET',
169+
path = '/param',
170+
file = 'helper.html.el'
171+
}, function(tx)
172+
local params = ""
173+
for k,v in pairs(tx:param()) do
174+
params = params .. k .. "=" .. v
175+
end
176+
return tx:render({text = params .. tx:read()})
177+
end)
178+
t.assert_type(r, 'table', 'add GET method')
179+
180+
r = http_client.request('GET', helpers.base_uri .. '/param?a=1')
181+
t.assert_equals(r.body, 'a=1', 'GET reply parameter')
182+
183+
r = http_client.request('GET', helpers.base_uri .. '/param?a+a=1')
184+
t.assert_equals(r.body, 'a a=1', 'GET reply parameter name with plus')
185+
186+
r = http_client.request('GET', helpers.base_uri .. '/param?a=1+1')
187+
t.assert_equals(r.body, 'a=1 1', 'GET reply parameter value with plus')
188+
end
189+
163190
g.test_DELETE = function()
164191
local httpd = g.httpd
165192
local r = httpd:route({

0 commit comments

Comments
 (0)