|
@ -68,16 +68,18 @@ end |
|
|
--- @return string? content_type the content type of the attached file, or nil if entry is not a file. |
|
|
--- @return string? content_type the content type of the attached file, or nil if entry is not a file. |
|
|
--- @return string data the value of the entry. |
|
|
--- @return string data the value of the entry. |
|
|
--- We are doing some severe assumptions here. |
|
|
--- We are doing some severe assumptions here. |
|
|
--- - Firstly we assume that if the first line of a header doesn't start with |
|
|
|
|
|
--- `Content-Disposition`, it is invalid and we can ignore it. |
|
|
|
|
|
--- - Secondly we assume that in the headers, any `CR` is always gonna be |
|
|
|
|
|
|
|
|
--- - Firstly we assume that in the headers, any `CR` is always gonna be |
|
|
--- followed by a `LF` thus we only check for CR and advance by 2 when found |
|
|
--- followed by a `LF` thus we only check for CR and advance by 2 when found |
|
|
--- - Thirdly we assume that the only headers that can matter are |
|
|
|
|
|
|
|
|
--- - Secondly we assume that the only headers that can matter are |
|
|
--- `Content-Disposition` (for the field name) and `Content-Type` (if this is a |
|
|
--- `Content-Disposition` (for the field name) and `Content-Type` (if this is a |
|
|
--- 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 |
|
|
|
|
|
|
|
|
--- - Thirdly we assume a field name can't contain a double quote, even escaped |
|
|
|
|
|
--- |
|
|
|
|
|
--- Additionaly if the entry is bogus or something goes wrong the function may |
|
|
|
|
|
--- abort and return `"", nil, ""` instead. |
|
|
_m.parse_form_entry = function(entry) |
|
|
_m.parse_form_entry = function(entry) |
|
|
if #entry < 10 then return "", nil, "" end |
|
|
|
|
|
|
|
|
-- If an entry is less than 32 bytes, it's bogus, skip |
|
|
|
|
|
if #entry < 32 then return "", nil, "" end |
|
|
local cursor = 3 |
|
|
local cursor = 3 |
|
|
local name, ctype |
|
|
local name, ctype |
|
|
while true do |
|
|
while true do |
|
@ -99,7 +101,8 @@ _m.parse_form_entry = function(entry) |
|
|
while entry:sub(cursor, cursor) ~= "\r" do cursor = cursor + 1 end |
|
|
while entry:sub(cursor, cursor) ~= "\r" do cursor = cursor + 1 end |
|
|
cursor = cursor + 2 --[[ CRLF ]] |
|
|
cursor = cursor + 2 --[[ CRLF ]] |
|
|
end |
|
|
end |
|
|
if cursor == oldcursor then print(entry) os.exit(1); end |
|
|
|
|
|
|
|
|
-- If we didn't advance the cursor, something went very wrong, skip |
|
|
|
|
|
if cursor == oldcursor then print(entry) return "", nil, "" end |
|
|
end |
|
|
end |
|
|
return name, ctype, entry:sub(cursor, -1) |
|
|
return name, ctype, entry:sub(cursor, -1) |
|
|
end |
|
|
end |
|
|