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

How to escape a single qoute in a row #446

Closed
p-obrien opened this issue Aug 2, 2020 · 8 comments
Closed

How to escape a single qoute in a row #446

p-obrien opened this issue Aug 2, 2020 · 8 comments

Comments

@p-obrien
Copy link

p-obrien commented Aug 2, 2020

Using Fast-CSV to write a .csv for importing by a SSIS job but it's having issues with apostrophe/single quote in the row.

For example fast-csv writes the row like this: "The quick' brown fox" which SSIS isn't liking, it expects the line to not have the surrounding quotes: The quick' brown fox

Can this be achieved using a transform on a row?
It seems only the contents of the row can be altered using a transform and not the quoting.

@p-obrien
Copy link
Author

p-obrien commented Aug 2, 2020

Temporarily I'm stripping the single quotes

const transform = row => ({
      TaskName: row.TaskName.replace("'", ""),
    });

    const ws = createWriteStream('transform.csv');
    fastcsv.writeToStream(ws, tasksList, { headers: headers, alwaysWriteHeaders: true, transform: transform })
      .on('error', (err) => rej(err))
      .on('finish', () => res());

@Liotarne
Copy link

Liotarne commented Aug 4, 2020

I have the same problem with this case :

fs.createReadStream(_importFile as string)
              .pipe(csv.parse())
              .on('error', error => reject(error))
              .on('data', row => {
                resp.push(row);
              })
              .on('end', (rowCount: number) => {
                this.logProvider.info(`Parsed ${rowCount} rows`);
                resolve(resp);
              });

Do you have any solution please ?

@doug-martin
Copy link
Contributor

@piobrien fixed in v0.4.5. Thank you for reporting the issue!

@mabelleeyanhwa
Copy link

How about double quotes?

it(`should surround a column value with double quote and leave column value intact
        if column value has single or double quote`, async () => {
      const rows = [ {
        header1: "This column has \"double quotes\"",
        header2: "There is 'single quote'",
      } ];

      const result = await csvFormatter.writeRowsToString(rows);

      expect(result).toEqual("\"This column has \"double quotes\"\"|\"There is 'single quote'\"\n");
    });

Screenshot 2020-12-14 at 4 43 22 PM

The column that has double quotes is quoted, but the column with single quotes is not quoted

@mabelleeyanhwa
Copy link

@doug-martin Could you help to check if this behaviour is correct for double quotes?

@mabelleeyanhwa
Copy link

Hi, @doug-martin @piobrien could you kindly look into this? Our tests are failing because of this change for single quote that did not change for double quote.

@doug-martin
Copy link
Contributor

@mabelleeyanhwa sorry I didn't see this notification until this morning...I'll try to take a look today.

@mabelleeyanhwa
Copy link

@doug-martin its okay, no worries! Thank you for maintaining this package 🍡

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

No branches or pull requests

4 participants