Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] The | character causes unnecessary quotation of the value #787

Open
1 of 2 tasks
pepkin88 opened this issue Dec 2, 2022 · 1 comment
Open
1 of 2 tasks

[BUG] The | character causes unnecessary quotation of the value #787

pepkin88 opened this issue Dec 2, 2022 · 1 comment
Assignees
Labels

Comments

@pepkin88
Copy link

pepkin88 commented Dec 2, 2022

Describe the bug
If the cell value includes the | character, the cell is unnecessarily quoted.

Parsing or Formatting?

  • Formatting
  • Parsing

To Reproduce

import { format } from '@fast-csv/format';
const stream = format();
stream.pipe(process.stdout);
stream.write(['|']);
stream.write(['a']);
stream.end();

Expected behavior
Printed in the console:

|
a

What I get instead is:

"|"
a

Desktop (please complete the following information):

  • OS: macOS
  • OS Version: Ventura
  • Node Version: 18.6.0

Additional context
The reason for such behavior:
In the file packages/format/src/formatter/FieldFormatter.ts there is a line:

const escapePattern = `[${formatterOptions.delimiter}${escapeRegExp(formatterOptions.rowDelimiter)}|\r|\n]`;

The problem is with the ending characters of the regexp: |\r|\n]. Because it is inside the square brackets [], the | characters don't have the meaning of alternation, but instead are treated as a single character in a character set.
The resulting regexp from the default settings would be /[,\n|\r|\n]/, which would match an occurrence of any of the following characters: ,, \n, |, \r.
So to fix it, it should be enough to just delete those | characters from the set, as they are not needed there:

const escapePattern = `[${formatterOptions.delimiter}${escapeRegExp(formatterOptions.rowDelimiter)}\r\n]`;

I wanted to post this as a pull request, but I failed at building the project and running the tests. There are some errors, but honestly, I don't have the time or maybe even competence to track and fix them. I hope this issue is good enough.

@haddyo
Copy link

haddyo commented Feb 13, 2023

Any Solution so far achieved yet? I need a quick fix to overcome this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants