Skip to content

Commit

Permalink
fix: replace double quotes instead triple quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
richardtks committed Jan 18, 2019
1 parent ba5de9a commit b0229a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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))}'''`;
}

Expand Down
14 changes: 14 additions & 0 deletions test/stringify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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\
`)
));

Expand Down

0 comments on commit b0229a6

Please sign in to comment.