Browse Source

Fixed #121, simplified quote handling logic (yay)

pull/124/head 4.0.7
Matthew Holt 10 years ago
parent
commit
f1eeb6f1ae
  1. 2
      bower.json
  2. 2
      package.json
  3. 32
      papaparse.js
  4. 4
      papaparse.min.js
  5. 2
      parse.jquery.json
  6. 9
      tests/test-cases.js

2
bower.json

@ -1,6 +1,6 @@
{ {
"name": "Papa-Parse", "name": "Papa-Parse",
"version": "4.0.6", "version": "4.0.7",
"main": "papaparse.js", "main": "papaparse.js",
"homepage": "http://papaparse.com", "homepage": "http://papaparse.com",
"authors": [ "authors": [

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "papaparse", "name": "papaparse",
"version": "4.0.6", "version": "4.0.7",
"description": "Fast and powerful CSV parser for the browser that supports web workers and streaming large files. Converts CSV to JSON and JSON to CSV.", "description": "Fast and powerful CSV parser for the browser that supports web workers and streaming large files. Converts CSV to JSON and JSON to CSV.",
"keywords": [ "keywords": [
"csv", "csv",

32
papaparse.js

@ -1,6 +1,6 @@
/* /*
Papa Parse Papa Parse
v4.0.6 v4.0.7
https://github.com/mholt/PapaParse https://github.com/mholt/PapaParse
*/ */
(function(global) (function(global)
@ -1169,7 +1169,7 @@
return finish(); return finish();
} }
if (quoteSearch == inputLen-1 && hasCloseQuote(input.substring(cursor, quoteSearch+1))) if (quoteSearch == inputLen-1)
{ {
// Closing quote at EOF // Closing quote at EOF
row.push(input.substring(cursor, quoteSearch).replace(/""/g, '"')); row.push(input.substring(cursor, quoteSearch).replace(/""/g, '"'));
@ -1181,9 +1181,12 @@
// If this quote is escaped, it's part of the data; skip it // If this quote is escaped, it's part of the data; skip it
if (input[quoteSearch+1] == '"') if (input[quoteSearch+1] == '"')
{
quoteSearch++;
continue; continue;
}
if (input[quoteSearch+1] == delim && hasCloseQuote(input.substring(cursor, quoteSearch+1))) if (input[quoteSearch+1] == delim)
{ {
// Closing quote followed by delimiter // Closing quote followed by delimiter
row.push(input.substring(cursor, quoteSearch).replace(/""/g, '"')); row.push(input.substring(cursor, quoteSearch).replace(/""/g, '"'));
@ -1193,7 +1196,7 @@
break; break;
} }
if (input.substr(quoteSearch+1, newlineLen) == newline && hasCloseQuote(input.substring(cursor, quoteSearch+1))) if (input.substr(quoteSearch+1, newlineLen) == newline)
{ {
// Closing quote followed by newline // Closing quote followed by newline
row.push(input.substring(cursor, quoteSearch).replace(/""/g, '"')); row.push(input.substring(cursor, quoteSearch).replace(/""/g, '"'));
@ -1321,27 +1324,6 @@
{ {
return cursor; return cursor;
}; };
// hasCloseQuote determines if a field has a closing quote.
// field should be a string without the opening quote
// but with the closing quote (which might not actually be
// a closing quote).
function hasCloseQuote(field)
{
if (field.length == 0)
return false;
if (field[field.length-1] != '"')
return false;
if (field.length > 2)
return field[field.length-2] != '"' || field[field.length-3] == '"';
if (field.length > 1)
return field[field.length-2] != '"';
return true;
}
} }

4
papaparse.min.js vendored

File diff suppressed because one or more lines are too long

2
parse.jquery.json

@ -1,6 +1,6 @@
{ {
"name": "parse", "name": "parse",
"version": "4.0.6", "version": "4.0.7",
"title": "Papa Parse", "title": "Papa Parse",
"description": "Powerful CSV parser that converts CSV to JSON and JSON to CSV. Supports web workers and streaming large files. Fastest CSV parser for JavaScript.", "description": "Powerful CSV parser that converts CSV to JSON and JSON to CSV. Supports web workers and streaming large files. Fastest CSV parser for JavaScript.",
"keywords": [ "keywords": [

9
tests/test-cases.js

@ -136,6 +136,15 @@ var CORE_PARSER_TESTS = [
errors: [] errors: []
} }
}, },
{
description: "Quoted field with 5 quotes in a row and a delimiter in there, too",
input: '"1","cnonce="""",nc=""""","2"',
notes: "Actual input reported in issue #121",
expected: {
data: [['1', 'cnonce="",nc=""', '2']],
errors: []
}
},
{ {
description: "Quoted field with whitespace around quotes", description: "Quoted field with whitespace around quotes",
input: 'A, "B" ,C', input: 'A, "B" ,C',

Loading…
Cancel
Save