Skip to content

Commit

Permalink
Merge pull request #190 from ckeditor/ck/fix-wrong-stringify-quotes-h…
Browse files Browse the repository at this point in the history
…andling

Other: Transform all single quotes passed to `stringify` function instead of only the first one.
  • Loading branch information
arkflpc authored Oct 28, 2024
2 parents f7b3710 + 3993705 commit ff81aa5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function truncateString( string, length ) {
// Retain the JSON.stringify() formatting instead of fixing 100 tests across the project :)
function stringifySingleToDoubleQuotesReplacer( value, indent, stringify ) {
if ( typeof value === 'string' ) {
return `"${ value.replace( '\'', '"' ) }"`;
return `"${ value.replaceAll( '\'', '\\"' ) }"`;
}

return stringify( value );
Expand Down
4 changes: 4 additions & 0 deletions tests/inspector/components/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ describe( 'Utils', () => {
expect( stringify( () => 'foo' ) ).to.equal( 'function() {…}' );
} );

it( 'serializes quotes properly', () => {
expect( stringify( '\'foo\'' ) ).to.equal( '"\\"foo\\""' );
} );

it( 'stringifies values (no quotes around text)', () => {
expect( stringify( undefined ) ).to.equal( 'undefined' );
expect( stringify( true ) ).to.equal( 'true' );
Expand Down

0 comments on commit ff81aa5

Please sign in to comment.