From ea1603a193dd7aecb0e959240daff33971b86713 Mon Sep 17 00:00:00 2001 From: Ella Date: Tue, 15 Aug 2023 08:29:50 +0200 Subject: [PATCH 1/4] Footnotes: autosave saves decoded JSON --- packages/block-library/src/footnotes/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/footnotes/index.php b/packages/block-library/src/footnotes/index.php index bd7734d7d02d1..20065747beb37 100644 --- a/packages/block-library/src/footnotes/index.php +++ b/packages/block-library/src/footnotes/index.php @@ -243,7 +243,7 @@ function _wp_rest_api_autosave_meta( $autosave ) { return; } - update_post_meta( $id, 'footnotes', $body['meta']['footnotes'] ); + update_post_meta( $id, 'footnotes', json_encode( $body['meta']['footnotes'] ) ); } // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L391C1-L391C1. add_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' ); From dfd972ebf64323bca4cf25381b25bb104f45f0aa Mon Sep 17 00:00:00 2001 From: Ella Date: Tue, 15 Aug 2023 09:36:46 +0200 Subject: [PATCH 2/4] wp_slash --- packages/block-library/src/footnotes/index.php | 2 +- test/e2e/specs/editor/various/footnotes.spec.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/footnotes/index.php b/packages/block-library/src/footnotes/index.php index 20065747beb37..855c53e920579 100644 --- a/packages/block-library/src/footnotes/index.php +++ b/packages/block-library/src/footnotes/index.php @@ -243,7 +243,7 @@ function _wp_rest_api_autosave_meta( $autosave ) { return; } - update_post_meta( $id, 'footnotes', json_encode( $body['meta']['footnotes'] ) ); + update_post_meta( $id, 'footnotes', wp_slash( $body['meta']['footnotes'] ) ); } // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L391C1-L391C1. add_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' ); diff --git a/test/e2e/specs/editor/various/footnotes.spec.js b/test/e2e/specs/editor/various/footnotes.spec.js index b96d4530cb499..faf870f6c0a75 100644 --- a/test/e2e/specs/editor/various/footnotes.spec.js +++ b/test/e2e/specs/editor/various/footnotes.spec.js @@ -392,12 +392,12 @@ test.describe( 'Footnotes', () => { // path). await editor.canvas.click( 'ol.wp-block-footnotes li span' ); await page.keyboard.press( 'End' ); - await page.keyboard.type( '3' ); + await page.keyboard.type( '3"' ); const previewPage2 = await editor.openPreviewPage(); await expect( previewPage2.locator( 'ol.wp-block-footnotes li' ) - ).toHaveText( '123 ↩︎' ); + ).toHaveText( '123" ↩︎' ); } ); } ); From 0e60e389c29a4512fa09f34a0881dd0ee54e1514 Mon Sep 17 00:00:00 2001 From: Ella Date: Tue, 15 Aug 2023 10:31:22 +0200 Subject: [PATCH 3/4] Curly quote --- test/e2e/specs/editor/various/footnotes.spec.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/e2e/specs/editor/various/footnotes.spec.js b/test/e2e/specs/editor/various/footnotes.spec.js index faf870f6c0a75..03a68914044ff 100644 --- a/test/e2e/specs/editor/various/footnotes.spec.js +++ b/test/e2e/specs/editor/various/footnotes.spec.js @@ -392,12 +392,14 @@ test.describe( 'Footnotes', () => { // path). await editor.canvas.click( 'ol.wp-block-footnotes li span' ); await page.keyboard.press( 'End' ); + // Test slashing. await page.keyboard.type( '3"' ); const previewPage2 = await editor.openPreviewPage(); + // Note: quote will get curled by wptexturize. await expect( previewPage2.locator( 'ol.wp-block-footnotes li' ) - ).toHaveText( '123" ↩︎' ); + ).toHaveText( '123″ ↩︎' ); } ); } ); From 6541a8a26ace180d6d37bf4c0243d8874665dbe3 Mon Sep 17 00:00:00 2001 From: Ella Date: Tue, 15 Aug 2023 14:15:34 +0200 Subject: [PATCH 4/4] Slash on save and restore --- .../block-library/src/footnotes/index.php | 6 ++-- .../specs/editor/various/footnotes.spec.js | 28 ++++++++++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/block-library/src/footnotes/index.php b/packages/block-library/src/footnotes/index.php index 855c53e920579..7c4967316f185 100644 --- a/packages/block-library/src/footnotes/index.php +++ b/packages/block-library/src/footnotes/index.php @@ -98,7 +98,7 @@ function wp_save_footnotes_meta( $revision_id ) { if ( $footnotes ) { // Can't use update_post_meta() because it doesn't allow revisions. - update_metadata( 'post', $revision_id, 'footnotes', $footnotes ); + update_metadata( 'post', $revision_id, 'footnotes', wp_slash( $footnotes ) ); } } } @@ -154,7 +154,7 @@ function wp_add_footnotes_revisions_to_post_meta( $post ) { if ( $footnotes ) { // Can't use update_post_meta() because it doesn't allow revisions. - update_metadata( 'post', $wp_temporary_footnote_revision_id, 'footnotes', $footnotes ); + update_metadata( 'post', $wp_temporary_footnote_revision_id, 'footnotes', wp_slash( $footnotes ) ); } } } @@ -176,7 +176,7 @@ function wp_restore_footnotes_from_revision( $post_id, $revision_id ) { $footnotes = get_post_meta( $revision_id, 'footnotes', true ); if ( $footnotes ) { - update_post_meta( $post_id, 'footnotes', $footnotes ); + update_post_meta( $post_id, 'footnotes', wp_slash( $footnotes ) ); } else { delete_post_meta( $post_id, 'footnotes' ); } diff --git a/test/e2e/specs/editor/various/footnotes.spec.js b/test/e2e/specs/editor/various/footnotes.spec.js index 03a68914044ff..e024964831dfe 100644 --- a/test/e2e/specs/editor/various/footnotes.spec.js +++ b/test/e2e/specs/editor/various/footnotes.spec.js @@ -291,7 +291,8 @@ test.describe( 'Footnotes', () => { await editor.clickBlockToolbarButton( 'More' ); await page.locator( 'button:text("Footnote")' ).click(); - await page.keyboard.type( 'first footnote' ); + // Check if content is correctly slashed on save and restore. + await page.keyboard.type( 'first footnote"' ); const id1 = await editor.canvas.evaluate( () => { return document.activeElement.id; @@ -316,7 +317,7 @@ test.describe( 'Footnotes', () => { id: id2, }, { - content: 'first footnote', + content: 'first footnote"', id: id1, }, ] ); @@ -329,7 +330,7 @@ test.describe( 'Footnotes', () => { // This also saves the post! expect( await getFootnotes( page ) ).toMatchObject( [ { - content: 'first footnote', + content: 'first footnote"', id: id1, }, { @@ -338,6 +339,16 @@ test.describe( 'Footnotes', () => { }, ] ); + const editorPage = page; + const previewPage = await editor.openPreviewPage(); + + await expect( + previewPage.locator( 'ol.wp-block-footnotes' ) + ).toHaveText( 'first footnote” ↩︎second footnote ↩︎' ); + + await previewPage.close(); + await editorPage.bringToFront(); + // Open revisions. await editor.openDocumentSettingsSidebar(); await page @@ -355,10 +366,19 @@ test.describe( 'Footnotes', () => { id: id2, }, { - content: 'first footnote', + content: 'first footnote"', id: id1, }, ] ); + + const previewPage2 = await editor.openPreviewPage(); + + await expect( + previewPage2.locator( 'ol.wp-block-footnotes' ) + ).toHaveText( 'second footnote ↩︎first footnote” ↩︎' ); + + await previewPage2.close(); + await editorPage.bringToFront(); } ); test( 'can be previewed when published', async ( { editor, page } ) => {