Skip to content

csv-stringify: quoted_match is ignored for empty strings #344

@MindaugasButkus

Description

@MindaugasButkus

Describe the bug

There is no way to quote empty strings without also quoting null and undefined values. I expect that empty string will be quoted and null / undefined values will not be quoted when options quoted_match: /^&/ and quoted_empty: false are provided. quoted_empty: true will quote empty strings, but it will also quote null and undefined values.

Node version: 16.13.2
csv-stringify version: 6.1.2

To Reproduce

import { stringify } from "csv-stringify";

stringify([
  ["a", null, undefined, "", "b"],
], {
  quoted_empty: false,
  quoted_match: /^$/,
}, (_, csv) => {
  console.log(csv);
});

Output: a,,,,b
Expected output: a,,,"",b

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions