Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/csv-parse/dist/cjs/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,16 @@ const transform = function (original_options = {}) {
pos,
);
if (recordDelimiterLength !== 0) {
// Only the first byte of the record delimiter was appended to
// the raw buffer above; append the remaining bytes so that
// multi-byte delimiters such as "\r\n" are preserved in full in
// `raw` instead of being truncated when `pos` skips past them
// below (e.g. `raw: 'a,b\r'` instead of `raw: 'a,b\r\n'`). (#332)
if (raw === true) {
for (let i = 1; i < recordDelimiterLength; i++) {
rawBuffer.append(buf[pos + i]);
}
}
// Do not emit comments which take a full line
const skipCommentLine =
this.state.commenting &&
Expand Down
10 changes: 10 additions & 0 deletions packages/csv-parse/dist/cjs/stream.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,16 @@ const transform = function (original_options = {}) {
pos,
);
if (recordDelimiterLength !== 0) {
// Only the first byte of the record delimiter was appended to
// the raw buffer above; append the remaining bytes so that
// multi-byte delimiters such as "\r\n" are preserved in full in
// `raw` instead of being truncated when `pos` skips past them
// below (e.g. `raw: 'a,b\r'` instead of `raw: 'a,b\r\n'`). (#332)
if (raw === true) {
for (let i = 1; i < recordDelimiterLength; i++) {
rawBuffer.append(buf[pos + i]);
}
}
// Do not emit comments which take a full line
const skipCommentLine =
this.state.commenting &&
Expand Down
10 changes: 10 additions & 0 deletions packages/csv-parse/dist/cjs/sync.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,16 @@ const transform = function (original_options = {}) {
pos,
);
if (recordDelimiterLength !== 0) {
// Only the first byte of the record delimiter was appended to
// the raw buffer above; append the remaining bytes so that
// multi-byte delimiters such as "\r\n" are preserved in full in
// `raw` instead of being truncated when `pos` skips past them
// below (e.g. `raw: 'a,b\r'` instead of `raw: 'a,b\r\n'`). (#332)
if (raw === true) {
for (let i = 1; i < recordDelimiterLength; i++) {
rawBuffer.append(buf[pos + i]);
}
}
// Do not emit comments which take a full line
const skipCommentLine =
this.state.commenting &&
Expand Down
10 changes: 10 additions & 0 deletions packages/csv-parse/dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6409,6 +6409,16 @@ const transform = function (original_options = {}) {
pos,
);
if (recordDelimiterLength !== 0) {
// Only the first byte of the record delimiter was appended to
// the raw buffer above; append the remaining bytes so that
// multi-byte delimiters such as "\r\n" are preserved in full in
// `raw` instead of being truncated when `pos` skips past them
// below (e.g. `raw: 'a,b\r'` instead of `raw: 'a,b\r\n'`). (#332)
if (raw === true) {
for (let i = 1; i < recordDelimiterLength; i++) {
rawBuffer.append(buf[pos + i]);
}
}
// Do not emit comments which take a full line
const skipCommentLine =
this.state.commenting &&
Expand Down
10 changes: 10 additions & 0 deletions packages/csv-parse/dist/esm/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -3328,6 +3328,16 @@ const transform = function (original_options = {}) {
pos,
);
if (recordDelimiterLength !== 0) {
// Only the first byte of the record delimiter was appended to
// the raw buffer above; append the remaining bytes so that
// multi-byte delimiters such as "\r\n" are preserved in full in
// `raw` instead of being truncated when `pos` skips past them
// below (e.g. `raw: 'a,b\r'` instead of `raw: 'a,b\r\n'`). (#332)
if (raw === true) {
for (let i = 1; i < recordDelimiterLength; i++) {
rawBuffer.append(buf[pos + i]);
}
}
// Do not emit comments which take a full line
const skipCommentLine =
this.state.commenting &&
Expand Down
10 changes: 10 additions & 0 deletions packages/csv-parse/dist/iife/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6412,6 +6412,16 @@ var csv_parse = (function (exports) {
pos,
);
if (recordDelimiterLength !== 0) {
// Only the first byte of the record delimiter was appended to
// the raw buffer above; append the remaining bytes so that
// multi-byte delimiters such as "\r\n" are preserved in full in
// `raw` instead of being truncated when `pos` skips past them
// below (e.g. `raw: 'a,b\r'` instead of `raw: 'a,b\r\n'`). (#332)
if (raw === true) {
for (let i = 1; i < recordDelimiterLength; i++) {
rawBuffer.append(buf[pos + i]);
}
}
// Do not emit comments which take a full line
const skipCommentLine =
this.state.commenting &&
Expand Down
10 changes: 10 additions & 0 deletions packages/csv-parse/dist/iife/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -3331,6 +3331,16 @@ var csv_parse_sync = (function (exports) {
pos,
);
if (recordDelimiterLength !== 0) {
// Only the first byte of the record delimiter was appended to
// the raw buffer above; append the remaining bytes so that
// multi-byte delimiters such as "\r\n" are preserved in full in
// `raw` instead of being truncated when `pos` skips past them
// below (e.g. `raw: 'a,b\r'` instead of `raw: 'a,b\r\n'`). (#332)
if (raw === true) {
for (let i = 1; i < recordDelimiterLength; i++) {
rawBuffer.append(buf[pos + i]);
}
}
// Do not emit comments which take a full line
const skipCommentLine =
this.state.commenting &&
Expand Down
10 changes: 10 additions & 0 deletions packages/csv-parse/dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6415,6 +6415,16 @@
pos,
);
if (recordDelimiterLength !== 0) {
// Only the first byte of the record delimiter was appended to
// the raw buffer above; append the remaining bytes so that
// multi-byte delimiters such as "\r\n" are preserved in full in
// `raw` instead of being truncated when `pos` skips past them
// below (e.g. `raw: 'a,b\r'` instead of `raw: 'a,b\r\n'`). (#332)
if (raw === true) {
for (let i = 1; i < recordDelimiterLength; i++) {
rawBuffer.append(buf[pos + i]);
}
}
// Do not emit comments which take a full line
const skipCommentLine =
this.state.commenting &&
Expand Down
10 changes: 10 additions & 0 deletions packages/csv-parse/dist/umd/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -3334,6 +3334,16 @@
pos,
);
if (recordDelimiterLength !== 0) {
// Only the first byte of the record delimiter was appended to
// the raw buffer above; append the remaining bytes so that
// multi-byte delimiters such as "\r\n" are preserved in full in
// `raw` instead of being truncated when `pos` skips past them
// below (e.g. `raw: 'a,b\r'` instead of `raw: 'a,b\r\n'`). (#332)
if (raw === true) {
for (let i = 1; i < recordDelimiterLength; i++) {
rawBuffer.append(buf[pos + i]);
}
}
// Do not emit comments which take a full line
const skipCommentLine =
this.state.commenting &&
Expand Down
10 changes: 10 additions & 0 deletions packages/csv-parse/lib/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,16 @@ const transform = function (original_options = {}) {
pos,
);
if (recordDelimiterLength !== 0) {
// Only the first byte of the record delimiter was appended to
// the raw buffer above; append the remaining bytes so that
// multi-byte delimiters such as "\r\n" are preserved in full in
// `raw` instead of being truncated when `pos` skips past them
// below (e.g. `raw: 'a,b\r'` instead of `raw: 'a,b\r\n'`). (#332)
if (raw === true) {
for (let i = 1; i < recordDelimiterLength; i++) {
rawBuffer.append(buf[pos + i]);
}
}
// Do not emit comments which take a full line
const skipCommentLine =
this.state.commenting &&
Expand Down
13 changes: 13 additions & 0 deletions packages/csv-parse/test/option.raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ describe("Option `raw`", function () {
});
});

it("preserves windows (CRLF) record delimiters", function (next) {
// The `\n` of a `\r\n` record delimiter used to be dropped from `raw`,
// yielding `a,b\r` instead of `a,b\r\n`. (#332)
parse("a,b\r\nc,d\r\n", { raw: true }, (err, records) => {
if (err) return next(err);
const raws = (
records as unknown as { record: string[]; raw: string }[]
).map((r) => r.raw);
raws.should.eql(["a,b\r\n", "c,d\r\n"]);
next();
});
});

it("preserve columns", function (next) {
parse(
dedent`
Expand Down