diff --git a/ftcsv-1.1.2-1.rockspec b/ftcsv-1.1.3-1.rockspec similarity index 95% rename from ftcsv-1.1.2-1.rockspec rename to ftcsv-1.1.3-1.rockspec index b73c94f..8267efb 100644 --- a/ftcsv-1.1.2-1.rockspec +++ b/ftcsv-1.1.3-1.rockspec @@ -1,9 +1,9 @@ package = "ftcsv" -version = "1.1.2-1" +version = "1.1.3-1" source = { url = "git://github.com/FourierTransformer/ftcsv.git", - tag = "1.1.2" + tag = "1.1.3" } description = { diff --git a/ftcsv.lua b/ftcsv.lua index 172434c..af4abec 100644 --- a/ftcsv.lua +++ b/ftcsv.lua @@ -1,5 +1,5 @@ local ftcsv = { - _VERSION = 'ftcsv 1.1.2', + _VERSION = 'ftcsv 1.1.3', _DESCRIPTION = 'CSV library for Lua', _URL = 'https://github.com/FourierTransformer/ftcsv', _LICENSE = [[ @@ -187,9 +187,11 @@ local function parseString(inputString, inputLength, delimiter, i, headerField, fieldStart = i + 2 -- print("fs+2:", fieldStart) - -- identifies the escape toggle - elseif currentChar == quote and nextChar ~= quote then - -- print("ESCAPE TOGGLE") + -- identifies the escape toggle. + -- This can only happen if fields have quotes around them + -- so the current "start" has to be where a quote character is. + elseif currentChar == quote and nextChar ~= quote and fieldStart == i then + -- print("New Quoted Field", i) fieldStart = i + 1 i, doubleQuoteEscape = M.findClosingQuote(i+1, inputLength, inputString, quote, doubleQuoteEscape) -- print("I VALUE", i, doubleQuoteEscape) @@ -345,7 +347,7 @@ function ftcsv.parse(inputFile, delimiter, options) end -- parse through the headers! - local headerField, i = parseString(inputString, inputLength, delimiter, 0) + local headerField, i = parseString(inputString, inputLength, delimiter, 1) i = i + 1 -- start at the next char -- make sure a header isn't empty diff --git a/spec/csvs/quotes_non_escaped.csv b/spec/csvs/quotes_non_escaped.csv new file mode 100644 index 0000000..c1f7447 --- /dev/null +++ b/spec/csvs/quotes_non_escaped.csv @@ -0,0 +1,2 @@ +"Country","City","AccentCity","Region" +af,dekh"iykh'ya,Dekh"iykh'ya,13 \ No newline at end of file diff --git a/spec/json/quotes_non_escaped.json b/spec/json/quotes_non_escaped.json new file mode 100644 index 0000000..5003f0d --- /dev/null +++ b/spec/json/quotes_non_escaped.json @@ -0,0 +1,8 @@ +[ + { + "Country": "af", + "City": "dekh\"iykh'ya", + "AccentCity": "Dekh\"iykh'ya", + "Region": "13" + } +] diff --git a/spec/parse_encode_spec.lua b/spec/parse_encode_spec.lua index b336c01..f18c690 100644 --- a/spec/parse_encode_spec.lua +++ b/spec/parse_encode_spec.lua @@ -23,6 +23,7 @@ local files = { "newlines", "newlines_crlf", "quotes_and_newlines", + "quotes_non_escaped", "simple", "simple_crlf", "utf8"