Skip to content

Commit

Permalink
fixed bug where quote existed in non-quoted field
Browse files Browse the repository at this point in the history
  • Loading branch information
FourierTransformer committed Nov 12, 2016
1 parent 49baa6d commit a94461c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ftcsv-1.1.2-1.rockspec → ftcsv-1.1.3-1.rockspec
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
12 changes: 7 additions & 5 deletions ftcsv.lua
Original file line number Diff line number Diff line change
@@ -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 = [[
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions spec/csvs/quotes_non_escaped.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"Country","City","AccentCity","Region"
af,dekh"iykh'ya,Dekh"iykh'ya,13
8 changes: 8 additions & 0 deletions spec/json/quotes_non_escaped.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"Country": "af",
"City": "dekh\"iykh'ya",
"AccentCity": "Dekh\"iykh'ya",
"Region": "13"
}
]
1 change: 1 addition & 0 deletions spec/parse_encode_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ local files = {
"newlines",
"newlines_crlf",
"quotes_and_newlines",
"quotes_non_escaped",
"simple",
"simple_crlf",
"utf8"
Expand Down

0 comments on commit a94461c

Please sign in to comment.