Skip to content

Commit

Permalink
fixes koles#45
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisAlvares committed Jan 31, 2017
1 parent 9999d7f commit 2fa1479
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/ya-csv.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var sys;
try {
sys = require('util');
sys = require('util');
} catch (e) {
sys = require('sys');
}
Expand Down Expand Up @@ -38,6 +38,7 @@ var CsvReader = csv.CsvReader = function(readStream, options) {
openRecord: [],
openField: '',
lastChar: '',
escapeAtEnd: false,
quotedField: false,
commentedLine: false
};
Expand Down Expand Up @@ -126,11 +127,19 @@ CsvReader.prototype.parse = function(data) {
if (c === this.escapechar) {
// double-quote at the field beginning does not count as an escape string`
if (c !== this.quotechar || ps.openField || ps.quotedField) {
var nextChar = data.charAt(i + 1);
if (this._isEscapable(nextChar)) {
this._addCharacter(nextChar);
i++;
isEscape = true;
var nextChar = data.charAt(i + 1);
if (this._isEscapable(nextChar)) {
this._addCharacter(nextChar);
i++;
isEscape = true;
ps.escapeAtEnd = false;
} else if (!nextChar) {
ps.escapeAtEnd = true;
} else if (i===0 && ps.escapeAtEnd && this._isEscapable(ps.lastChar)) {
this._addCharacter(c);
ps.escapeAtEnd = false;
} else {
ps.escapeAtEnd = false;
}
}
}
Expand Down

0 comments on commit 2fa1479

Please sign in to comment.