I have an aura component that exports a list of cases to a CSV. In the description field, customers have been inserting double quotes in the field (example "variable") which breaks the columns of the CSV export.

When I try to add a replace in the component controller like this

row['Description'] = row['Description'].replace(/",/g,'""');

or like this

row['Description'] = row['Description'].replace(/"/g, '\"');

The framework throws this error 'Unterminated string [311, 103]: '');'

Can I escape a doublequote so my CSV exports properly?


This is a problem with Aura's parser, it sometimes gets things wrong. I would have presumed this would have been fixed by now, but apparently it's still an issue? The general workaround is to use a RegExp instead:

var doubleQuoteRegExp = new RegExp('"','g'); // g = global flag, equal to /"/g;
row['Description'] = row['Description'].replace(doubleQuoteRegExp, '""');
  • That was it! It totally fixed my CSV export. Thank you so much! If this were Reddit sfdcfox, I'd give you gold!
    – afandre
    Jan 15 at 14:28
  • @afandre It's okay. Here you can give me a ✔ if you want (and also to let people know this answer was accepted).
    – sfdcfox
    Jan 15 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.