Permalink
Browse files

Merge pull request #13 from ignacio/issue_13

wsapi.request.qs_encode yields invalid querystrings
  • Loading branch information...
mascarenhas committed Sep 24, 2013
2 parents 948df71 + 914fe40 commit d0907ab52735125777b23c553c2c61658d719370
Showing with 7 additions and 4 deletions.
  1. +6 −3 src/wsapi/request.lua
  2. +1 −1 tests/mock_test.lua
View
@@ -168,7 +168,8 @@ function methods:route_link(route, query, ...)
local builder = self.mk_app["link_" .. route]
if builder then
local uri = builder(self.mk_app, self.env, ...)
return uri .. self:qs_encode(query)
local qs = self:qs_encode(query)
return uri .. (qs ~= "" and ("?"..qs) or "")
else
error("there is no route named " .. route)
end
@@ -177,11 +178,13 @@ end
function methods:link(url, query)
local prefix = (self.mk_app and self.mk_app.prefix) or self.script_name
local uri = prefix .. url
return prefix .. url .. self:qs_encode(query)
local qs = self:qs_encode(query)
return prefix .. url .. (qs ~= "" and ("?"..qs) or "")
end
function methods:absolute_link(url, query)
return url .. self:qs_encode(query)
local qs = self:qs_encode(query)
return url .. (qs ~= "" and ("?"..qs) or "")
end
function methods:static_link(url)
View
@@ -15,7 +15,7 @@ do
local response, request = app:get("/", {hello = "world"})
assert(response.code == 200)
assert(request.request_method == "GET")
assert(request.query_string == "?hello=world")
assert(request.query_string == "hello=world")
assert(response.headers["Content-type"] == "text/html")
assert(response.body == "hello world!")
end

0 comments on commit d0907ab

Please sign in to comment.