diff --git a/src/components/utils.js b/src/components/utils.js index 6725eb2..1f0b30a 100644 --- a/src/components/utils.js +++ b/src/components/utils.js @@ -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 ); diff --git a/tests/inspector/components/utils.js b/tests/inspector/components/utils.js index a70165d..26e4b80 100644 --- a/tests/inspector/components/utils.js +++ b/tests/inspector/components/utils.js @@ -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' );