diff --git a/lib/stringify.js b/lib/stringify.js index b69ef1f..03973bf 100644 --- a/lib/stringify.js +++ b/lib/stringify.js @@ -33,7 +33,7 @@ 'use strict'; const jsIdentifierRE = /^[a-z_$][a-z0-9_$]*$/i; -const tripleQuotesRE = /'''/g; +const doubleQuotesRE = /''/g; const SPACES = ' '; function contains(str1, str2) { @@ -147,7 +147,7 @@ function visitString(visitNode, indent, str) { if (str.indexOf('\n') === -1 || !indent) { return onelineStringify(str); } - const string = str.replace(/\\/g, '\\\\').replace(tripleQuotesRE, "\\'''"); + const string = str.replace(/\\/g, '\\\\').replace(doubleQuotesRE, "\\''"); return `'''${newlineWrap(indentLines(indent, string))}'''`; } diff --git a/test/stringify.test.js b/test/stringify.test.js index 4839a2f..edf55f6 100644 --- a/test/stringify.test.js +++ b/test/stringify.test.js @@ -43,6 +43,20 @@ describe('CSON.stringify', () => { cson(`\ I am your average multi-line string, and I have a sneaky ''' in here, too\ +`) + )); + + it('handles multi-line strings with quad quotes', () => + equal( + `\ +''' + I am your average multi-line string, + and I have a sneaky \\''\\'' in here, too +'''\ +`, + cson(`\ +I am your average multi-line string, +and I have a sneaky '''' in here, too\ `) ));