|
@ -77,21 +77,29 @@ end |
|
|
--- file upload for the type of the uploaded file. |
|
|
--- file upload for the type of the uploaded file. |
|
|
--- - Fourthly we assume a field name can't contain a double quote |
|
|
--- - Fourthly we assume a field name can't contain a double quote |
|
|
_m.parse_form_entry = function(entry) |
|
|
_m.parse_form_entry = function(entry) |
|
|
|
|
|
if #entry < 10 then return "", nil, "" end |
|
|
local cursor = 3 |
|
|
local cursor = 3 |
|
|
local name, ctype |
|
|
local name, ctype |
|
|
while true do |
|
|
while true do |
|
|
|
|
|
local oldcursor = cursor |
|
|
if entry:sub(cursor, cursor) == "\r" then |
|
|
if entry:sub(cursor, cursor) == "\r" then |
|
|
cursor = cursor + 2 |
|
|
cursor = cursor + 2 |
|
|
break |
|
|
break |
|
|
elseif entry:sub(cursor, cursor+18) == 'Content-Disposition' then |
|
|
elseif entry:sub(cursor, cursor+18) == 'Content-Disposition' then |
|
|
cursor = cursor + 38 |
|
|
cursor = cursor + 38 |
|
|
name = string.match(entry, "(.*)\"", cursor) |
|
|
name = string.match(entry, "(.*)\"", cursor) |
|
|
cursor = cursor + #name + 1 --[[ the closing quote ]] + 2 --[[ CRLF ]] |
|
|
|
|
|
|
|
|
cursor = cursor + #name + 1 --[[ the closing quote ]] |
|
|
|
|
|
-- Find the end of line |
|
|
|
|
|
while entry:sub(cursor, cursor) ~= "\r" do cursor = cursor + 1 end |
|
|
|
|
|
cursor = cursor + 2 |
|
|
elseif entry:sub(cursor, cursor+11) == 'Content-Type' then |
|
|
elseif entry:sub(cursor, cursor+11) == 'Content-Type' then |
|
|
cursor = cursor + 14 |
|
|
cursor = cursor + 14 |
|
|
ctype = string.match(entry, "(.*)\r", cursor) |
|
|
ctype = string.match(entry, "(.*)\r", cursor) |
|
|
cursor = cursor + #ctype + 2 --[[ CRLF ]] |
|
|
|
|
|
|
|
|
cursor = cursor + #ctype |
|
|
|
|
|
while entry:sub(cursor, cursor) ~= "\r" do cursor = cursor + 1 end |
|
|
|
|
|
cursor = cursor + 2 --[[ CRLF ]] |
|
|
end |
|
|
end |
|
|
|
|
|
if cursor == oldcursor then print(entry) os.exit(1); end |
|
|
end |
|
|
end |
|
|
return name, ctype, entry:sub(cursor, -1) |
|
|
return name, ctype, entry:sub(cursor, -1) |
|
|
end |
|
|
end |
|
|