[grilo-plugins] lua-factory: double check optional argument in fetch



commit ce0e7d42490bd86baf29e38806a7530e7cb876ab
Author: Victor Toso <me victortoso com>
Date:   Wed Oct 7 22:04:16 2015 +0200

    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 files changed, 4 insertions(+), 1 deletions(-)
---
diff --git a/src/lua-factory/grl-lua-library.c b/src/lua-factory/grl-lua-library.c
index a33ed77..e3a6a4b 100644
--- a/src/lua-factory/grl-lua-library.c
+++ b/src/lua-factory/grl-lua-library.c
@@ -996,12 +996,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);
@@ -1039,7 +1042,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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]