[examples] Fix non-table response handling in shortener
authorMyhailo Danylenko <isbear@ukrpost.net>
Fri, 12 Oct 2012 21:24:44 +0300
changeset 136 2b04fad2f61a
parent 135 0e407455faca
child 137 4fda19d05965
[examples] Fix non-table response handling in shortener Reported by Mikael Berthe
examples/mcabberrc.lua
examples/shortenurl.lua
--- 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 ) )