From 46148e12b08f6d02935e914db351b581e1589010 Mon Sep 17 00:00:00 2001 From: Victor Toso Date: Wed, 7 Oct 2015 22:04:16 +0200 Subject: lua-factory: double check optional argument in fetch Strange error on xml-parser tests when fetching mocked content. The third argument was recognized as _G which is lua's table for its environment. Best thing to do is check number of arguments with lua_gettop instead of relying on lua_istable. https://bugzilla.gnome.org/show_bug.cgi?id=755447 --- src/lua-factory/grl-lua-library.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lua-factory/grl-lua-library.c b/src/lua-factory/grl-lua-library.c index 079344e..03978b7 100644 --- a/src/lua-factory/grl-lua-library.c +++ b/src/lua-factory/grl-lua-library.c @@ -992,12 +992,15 @@ grl_l_fetch (lua_State *L) const gchar *lua_callback; GrlNetWc *wc; gboolean is_table = FALSE; + gboolean wc_options = FALSE; OperationSpec *os; luaL_argcheck (L, (lua_isstring (L, 1) || lua_istable (L, 1)), 1, "expecting url as string or an array of urls"); luaL_argcheck (L, lua_isstring (L, 2), 2, "expecting callback function as string"); + /* Optional third argument */ + wc_options = (lua_gettop(L) == 3); os = grl_lua_library_get_current_operation (L); g_return_val_if_fail (os != NULL, 0); @@ -1035,7 +1038,7 @@ grl_l_fetch (lua_State *L) lua_callback = lua_tolstring (L, 2, NULL); - wc = net_wc_new_with_options(L, 3); + wc = (wc_options) ? net_wc_new_with_options(L, 3) : grl_net_wc_new (); /* shared data between urls */ results = g_new0 (gchar *, num_urls); -- cgit v1.2.1