mirror of
https://github.com/lunarmodules/luasocket.git
synced 2025-07-24 01:39:49 +02:00
LTN12 bug removed.
This commit is contained in:
@ -40,30 +40,27 @@ end
|
||||
function filter.chain(...)
|
||||
local n = table.getn(arg)
|
||||
local top, index = 1, 1
|
||||
local retry = ""
|
||||
return function(chunk)
|
||||
retry = chunk and retry
|
||||
while true do
|
||||
if index == top then
|
||||
chunk = arg[index](chunk)
|
||||
if chunk == "" or top == n then
|
||||
return chunk
|
||||
elseif chunk then
|
||||
index = index + 1
|
||||
if chunk == "" or top == n then return chunk
|
||||
elseif chunk then index = index + 1
|
||||
else
|
||||
top = top+1
|
||||
index = top
|
||||
end
|
||||
else
|
||||
local original = chunk
|
||||
chunk = arg[index](original or "")
|
||||
chunk = arg[index](chunk or "")
|
||||
if chunk == "" then
|
||||
index = index - 1
|
||||
chunk = original and chunk
|
||||
chunk = retry
|
||||
elseif chunk then
|
||||
if index == n then return chunk
|
||||
else index = index + 1 end
|
||||
else
|
||||
base.error("filter returned inappropriate nil")
|
||||
end
|
||||
else base.error("filter returned inappropriate nil") end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -138,6 +135,8 @@ function source.rewind(src)
|
||||
end
|
||||
end
|
||||
|
||||
local print = print
|
||||
|
||||
-- chains a source with a filter
|
||||
function source.chain(src, f)
|
||||
base.assert(src and f)
|
||||
@ -151,13 +150,16 @@ function source.chain(src, f)
|
||||
last_out = f(last_in)
|
||||
if last_out ~= "" then return last_out end
|
||||
if not last_in then
|
||||
error('filter returned inappropriate ""')
|
||||
base.error('filter returned inappropriate ""')
|
||||
end
|
||||
end
|
||||
elseif last_out then
|
||||
last_out = f(last_in and "")
|
||||
if last_in and not last_out then
|
||||
error('filter returned inappropriate nil')
|
||||
base.error('filter returned inappropriate nil')
|
||||
end
|
||||
if last_out == "" and not last_in then
|
||||
base.error(base.tostring(f) .. ' returned inappropriate ""')
|
||||
end
|
||||
return last_out
|
||||
else
|
||||
|
@ -267,6 +267,7 @@ static int mime_global_b64(lua_State *L)
|
||||
if (!input) {
|
||||
asize = b64pad(atom, asize, &buffer);
|
||||
luaL_pushresult(&buffer);
|
||||
if (!(*lua_tostring(L, -1))) lua_pushnil(L);
|
||||
lua_pushnil(L);
|
||||
return 2;
|
||||
}
|
||||
@ -306,6 +307,7 @@ static int mime_global_unb64(lua_State *L)
|
||||
/* if second is nil, we are done */
|
||||
if (!input) {
|
||||
luaL_pushresult(&buffer);
|
||||
if (!(*lua_tostring(L, -1))) lua_pushnil(L);
|
||||
lua_pushnil(L);
|
||||
return 2;
|
||||
}
|
||||
@ -418,7 +420,7 @@ static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer)
|
||||
if (qpclass[input[i]] == QP_PLAIN) luaL_putchar(buffer, input[i]);
|
||||
else qpquote(input[i], buffer);
|
||||
}
|
||||
luaL_addstring(buffer, EQCRLF);
|
||||
if (size > 0) luaL_addstring(buffer, EQCRLF);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -454,7 +456,9 @@ static int mime_global_qp(lua_State *L)
|
||||
if (!input) {
|
||||
asize = qppad(atom, asize, &buffer);
|
||||
luaL_pushresult(&buffer);
|
||||
if (!(*lua_tostring(L, -1))) lua_pushnil(L);
|
||||
lua_pushnil(L);
|
||||
return 2;
|
||||
}
|
||||
/* otherwise process rest of input */
|
||||
last = input + isize;
|
||||
@ -531,6 +535,7 @@ static int mime_global_unqp(lua_State *L)
|
||||
/* if second part is nil, we are done */
|
||||
if (!input) {
|
||||
luaL_pushresult(&buffer);
|
||||
if (!(*lua_tostring(L, -1))) lua_pushnil(L);
|
||||
lua_pushnil(L);
|
||||
return 2;
|
||||
}
|
||||
|
@ -49,6 +49,15 @@ mime.decodet['quoted-printable'] = function()
|
||||
return ltn12.filter.cycle(unqp, "")
|
||||
end
|
||||
|
||||
local io, string = io, string
|
||||
|
||||
local function format(chunk)
|
||||
if chunk then
|
||||
if chunk == "" then return "''"
|
||||
else return string.len(chunk) end
|
||||
else return "nil" end
|
||||
end
|
||||
|
||||
-- define the line-wrap filters
|
||||
mime.wrapt['text'] = function(length)
|
||||
length = length or 76
|
||||
|
Reference in New Issue
Block a user