oclif/cli-ux

CSV output escaping

leononame opened this issue · 0 comments

If outputting table data as CSV, double quotes don't get escaped properly. Check this source file:

import { Command } from '@oclif/command';
import { cli } from 'cli-ux';

export default class TestCsv extends Command {
  static flags = {
    ...cli.table.flags(),
  };

  async run() {
    const { flags } = this.parse(TestCsv);
    cli.table(
      [
        {
          s1: '"string"',
          s2: '',
        },
        {
          s1: '',
          s2: '"null"',
        },
        {
          s1: '"string"',
          s2: '["null","string"]',
        },
      ],
      {
        s1: {},
        s2: {},
      },
      {
        printLine: console.log,
        ...flags,
      }
    );
  }
}

./bin/run test --output=csv results in

S1,S2
"""string"",""
"","""null""
"""string"","[""null","string"]"