Skip to content

Commit

Permalink
Fix incorrect handling of double quotes in stringify function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mati365 committed Oct 28, 2024
1 parent f7b3710 commit 3993705
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 3993705

Please sign in to comment.