Fix csv header key assignment

This commit is contained in:
2025-11-15 16:01:31 +01:00
parent 4311533445
commit 83fed68432
2 changed files with 14 additions and 2 deletions

View File

@@ -106,7 +106,7 @@ function fromCSV(csv, options)
local shouldAdd = true
if hascomments and #fields > 0 then
local firstField = fields[1]
local trimmed = string.gsub(firstField, "^%s*(.-)%s*$", "%1")
local trimmed = trim(firstField)
if string.sub(trimmed, 1, 1) == "#" then shouldAdd = false end
end
if shouldAdd then table.insert(allRows, fields) end
@@ -181,7 +181,10 @@ function fromCSV(csv, options)
local dataRow = allRows[ii]
for j = 1, #dataRow do
row[j] = dataRow[j]
if headers[j] ~= nil and headers[j] ~= "" then row[headers[j]] = dataRow[j] end
if headers[j] ~= nil and headers[j] ~= "" then
local headerName = trim(headers[j])
row[headerName] = dataRow[j]
end
end
table.insert(rows, row)
end