luci-base: ensure that file upload values have length
authorJo-Philipp Wich <jo@mein.io>
Tue, 24 Apr 2018 11:37:33 +0000 (13:37 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 24 Apr 2018 11:44:40 +0000 (13:44 +0200)
Ensure that the (table) length of a file upload value has nonzero length
by initializing the first table index with the file name.

This fixes tests in the form

    x = luci.http.formvalue(...)
    if x and #x > 0 then ... end

Fixes #1763.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/luasrc/http.lua

index 56d0064825a8ea47a9027bbbe380c5dccce3cfaf..be5577ee0932931b207b9b7f694cb391a6c52799 100644 (file)
@@ -359,6 +359,7 @@ function mimedecode_message_body(src, msg, file_cb)
                        then
                                field.name = lhttp.header_attribute(buffer, "name")
                                field.file = lhttp.header_attribute(buffer, "filename")
+                               field[1] = field.file
                        end
 
                        if field.headers then