Skip to content

Commit

Permalink
Merge pull request #13 from ignacio/issue_13
Browse files Browse the repository at this point in the history
wsapi.request.qs_encode yields invalid querystrings
  • Loading branch information
mascarenhas committed Sep 24, 2013
2 parents 948df71 + 914fe40 commit d0907ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/wsapi/request.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.