Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

Commit

Permalink
don't try to decode a body containing only white-space
Browse files Browse the repository at this point in the history
(workaround for Redmine)
  • Loading branch information
fperrad committed Sep 4, 2011
1 parent f9b83d1 commit 4cd1a7f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Spore/Middleware/Format/JSON.lua
Expand Up @@ -20,7 +20,7 @@ function m:call (req)
end
req.headers['accept'] = 'application/json'
return function (res)
if res.body and res.body ~= '' then
if type(res.body) == 'string' and not res.body:match'^%s*$' then
local r, msg = pcall(function ()
local decode = require 'json.decode'.decode
res.body = decode(res.body)
Expand Down
2 changes: 1 addition & 1 deletion src/Spore/Middleware/Format/XML.lua
Expand Up @@ -141,7 +141,7 @@ function m:call (req)
end
req.headers['accept'] = 'text/xml'
return function (res)
if res.body and res.body ~= '' then
if type(res.body) == 'string' and not res.body:match'^%s*$' then
local r, msg = xml.parse(res.body)
if r then
res.body = { [r.tag] = collapse(r, self) }
Expand Down
2 changes: 1 addition & 1 deletion src/Spore/Middleware/Format/YAML.lua
Expand Up @@ -20,7 +20,7 @@ function m:call (req)
end
req.headers['accept'] = 'text/x-yaml'
return function (res)
if res.body and res.body ~= '' then
if type(res.body) == 'string' and not res.body:match'^%s*$' then
local r, msg = pcall(function ()
res.body = yaml.load(res.body)
end)
Expand Down

0 comments on commit 4cd1a7f

Please sign in to comment.