[examples] Fix non-table response handling in shortener
Reported by Mikael Berthe
--- a/examples/mcabberrc.lua Thu Oct 11 18:11:10 2012 +0300
+++ b/examples/mcabberrc.lua Fri Oct 12 21:24:44 2012 +0300
@@ -86,7 +86,6 @@
-- COMMON SUPPORT ROUTINES
--- unused :/
function shell_escape ( str )
if str then
return "'" .. str:gsub ( "'", "'\\''" ) .. "'"
--- a/examples/shortenurl.lua Thu Oct 11 18:11:10 2012 +0300
+++ b/examples/shortenurl.lua Fri Oct 12 21:24:44 2012 +0300
@@ -48,14 +48,14 @@
return true
else -- eof
local reply = json.decode ( replystring )
- if reply and reply.id then
+ if ( type ( reply ) == 'table' ) and reply.id then
if jid and main.yesno ( main.option ( 'lua_shorten_post_url' ) ) then
main.run ( ('say_to -q %s %s'):format ( jid, reply.id ) )
else
print ( ('Shortened url: %s'):format ( reply.id ) )
end
else
- if type ( reply.error ) == 'table' then
+ if type ( reply ) == 'table' and ( type ( reply.error ) == 'table' ) then
print ( ('Failed to shorten url: %u %s'):format ( reply.error.code, reply.error.message ) )
else
print ( ('Failed to shorten url: Unknown response:\n%s'):format ( replystring ) )