From 8f4a0980ca43b9b5787c695dff0f966adeea923d Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Thu, 4 Sep 2014 18:11:03 +0500 Subject: [PATCH] Fix. Returns nil from write callback treat as write error. --- src/lceasy.c | 5 ++++- test/test_easy.lua | 40 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/lceasy.c b/src/lceasy.c index 6f04032..bb4b458 100644 --- a/src/lceasy.c +++ b/src/lceasy.c @@ -625,7 +625,10 @@ static size_t lcurl_write_callback_(lua_State*L, } if(lua_gettop(L) > top){ - if(lua_isnil(L, top + 1)) return 0; + if(lua_isnil(L, top + 1)){ + if(lua_gettop(L) == (top+1)) lua_settop(L, top); + return 0; + } if(lua_isnumber(L, top + 1)){ ret = (size_t)lua_tonumber(L, top + 1); } diff --git a/test/test_easy.lua b/test/test_easy.lua index 5eeded9..a55298c 100644 --- a/test/test_easy.lua +++ b/test/test_easy.lua @@ -38,8 +38,7 @@ function test_write_to_file() assert_equal(c, c:perform()) end -function test_write_to_file_abort() - f = assert(io.open(fname, "w+b")) +function test_write_to_file_abort_01() c = assert(scurl.easy{ url = url; writefunction = function(str) @@ -48,8 +47,43 @@ function test_write_to_file_abort() }) local _, e = assert_nil(c:perform()) - assert_equal(e, curl.error(curl.ERROR_EASY, curl.E_WRITE_ERROR)) + assert_equal(curl.error(curl.ERROR_EASY, curl.E_WRITE_ERROR), e) +end +function test_write_to_file_abort_02() + c = assert(scurl.easy{ + url = url; + writefunction = function(str) + return false + end; + }) + + local _, e = assert_nil(c:perform()) + assert_equal(curl.error(curl.ERROR_EASY, curl.E_WRITE_ERROR), e) +end + +function test_write_to_file_abort_03() + c = assert(scurl.easy{ + url = url; + writefunction = function(str) + return nil, "WRITEERROR" + end; + }) + + local _, e = assert_nil(c:perform()) + assert_equal("WRITEERROR", e) +end + +function test_write_to_file_abort_04() + c = assert(scurl.easy{ + url = url; + writefunction = function(str) + return nil + end; + }) + + local _, e = assert_nil(c:perform()) + assert_equal(curl.error(curl.ERROR_EASY, curl.E_WRITE_ERROR), e) end function test_reset_write_callback()