Skip to content

Commit a94461c

Browse files
fixed bug where quote existed in non-quoted field
1 parent 49baa6d commit a94461c

5 files changed

+20
-7
lines changed

ftcsv-1.1.2-1.rockspec ftcsv-1.1.3-1.rockspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package = "ftcsv"
2-
version = "1.1.2-1"
2+
version = "1.1.3-1"
33

44
source = {
55
url = "git://github.com/FourierTransformer/ftcsv.git",
6-
tag = "1.1.2"
6+
tag = "1.1.3"
77
}
88

99
description = {

ftcsv.lua

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
local ftcsv = {
2-
_VERSION = 'ftcsv 1.1.2',
2+
_VERSION = 'ftcsv 1.1.3',
33
_DESCRIPTION = 'CSV library for Lua',
44
_URL = 'https://github.com/FourierTransformer/ftcsv',
55
_LICENSE = [[
@@ -187,9 +187,11 @@ local function parseString(inputString, inputLength, delimiter, i, headerField,
187187
fieldStart = i + 2
188188
-- print("fs+2:", fieldStart)
189189

190-
-- identifies the escape toggle
191-
elseif currentChar == quote and nextChar ~= quote then
192-
-- print("ESCAPE TOGGLE")
190+
-- identifies the escape toggle.
191+
-- This can only happen if fields have quotes around them
192+
-- so the current "start" has to be where a quote character is.
193+
elseif currentChar == quote and nextChar ~= quote and fieldStart == i then
194+
-- print("New Quoted Field", i)
193195
fieldStart = i + 1
194196
i, doubleQuoteEscape = M.findClosingQuote(i+1, inputLength, inputString, quote, doubleQuoteEscape)
195197
-- print("I VALUE", i, doubleQuoteEscape)
@@ -345,7 +347,7 @@ function ftcsv.parse(inputFile, delimiter, options)
345347
end
346348

347349
-- parse through the headers!
348-
local headerField, i = parseString(inputString, inputLength, delimiter, 0)
350+
local headerField, i = parseString(inputString, inputLength, delimiter, 1)
349351
i = i + 1 -- start at the next char
350352

351353
-- make sure a header isn't empty

spec/csvs/quotes_non_escaped.csv

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"Country","City","AccentCity","Region"
2+
af,dekh"iykh'ya,Dekh"iykh'ya,13

spec/json/quotes_non_escaped.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"Country": "af",
4+
"City": "dekh\"iykh'ya",
5+
"AccentCity": "Dekh\"iykh'ya",
6+
"Region": "13"
7+
}
8+
]

spec/parse_encode_spec.lua

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ local files = {
2323
"newlines",
2424
"newlines_crlf",
2525
"quotes_and_newlines",
26+
"quotes_non_escaped",
2627
"simple",
2728
"simple_crlf",
2829
"utf8"

0 commit comments

Comments
 (0)