diff --git a/lua/csv.lua b/lua/csv.lua index 53916d8..79a5d16 100644 --- a/lua/csv.lua +++ b/lua/csv.lua @@ -285,7 +285,9 @@ local function separated_values_iterator(file, parameters) elseif parameters.header and not header then header = fields else - coroutine.yield(fields, starts) + if fields[1] ~= "" or fields[2] then -- ignore blank lines + coroutine.yield(fields, starts) + end end field_count, fields, starts = 0, {}, {} end diff --git a/lua/test.lua b/lua/test.lua index 327fab3..fc0eac2 100644 --- a/lua/test.lua +++ b/lua/test.lua @@ -50,6 +50,9 @@ apple:four,charlie:60]], apple = { name = "ALPHA", transform = string.lower }, charlie = { transform = function(x) return tonumber(x) * 10 end }}}) +test("../test-data/blank-line.csv", [[ +this,file,ends,with,a,blank,line]]) + if errors == 0 then io.stdout:write("Passed\n") diff --git a/test-data/blank-line.csv b/test-data/blank-line.csv new file mode 100644 index 0000000..d04ca0d --- /dev/null +++ b/test-data/blank-line.csv @@ -0,0 +1 @@ +this,file,ends,with,a,blank,line