-
Notifications
You must be signed in to change notification settings - Fork 860
fix: Reinstate Jetpack assets to editor assets endpoint #44274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dcalhoun
merged 6 commits into
trunk
from
fix/reinstate-jetpack-assets-to-editor-assets-endpoint
Jul 15, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6ca136b
fix: Reinstate Jetpack assets to editor assets endpoint
dcalhoun 6e01109
changelog
dcalhoun 514b7f9
fix: Ensure WPCOM-specific Gutenberg plugin paths are allowed
dcalhoun dfd0e3d
test: Co-locate mocks with relevant test cases
dcalhoun eb991df
refactor: Remove unnecessary static function designation
dcalhoun d007bb1
docs: Clarify intent for each allowed prefix handle
dcalhoun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/fix-reinstate-jetpack-assets-to-editor-assets-endpoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: patch | ||
| Type: other | ||
|
|
||
| Editor assets endpoint: reinstate missing Jetpack assets via handle-based exclusion logic |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,36 +29,9 @@ public function set_up() { | |
| parent::set_up(); | ||
| $this->instance = new WPCOM_REST_API_V2_Endpoint_Block_Editor_Assets(); | ||
|
|
||
| // Mock the enqueue_block_editor_assets action to prevent loading non-existent files | ||
| // Remove existing actions to prevent failed loading of files that may or | ||
| // may not exist depending on the build output. | ||
| remove_all_actions( 'enqueue_block_editor_assets' ); | ||
| add_action( 'enqueue_block_editor_assets', array( $this, 'mock_block_editor_assets' ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Clean up after each test. | ||
| */ | ||
| public function tear_down() { | ||
| // Remove our mock action | ||
| remove_action( 'enqueue_block_editor_assets', array( $this, 'mock_block_editor_assets' ) ); | ||
| parent::tear_down(); | ||
| } | ||
|
|
||
| /** | ||
| * Mock function for block editor assets. | ||
| * This provides minimal required assets without loading actual files. | ||
| */ | ||
| public function mock_block_editor_assets() { | ||
| // Register minimal mock assets that don't require actual files | ||
| wp_register_script( 'mock-editor-script', 'http://example.org/plugins/jetpack/mock-editor.js', array(), '1.0', true ); | ||
| wp_register_style( 'mock-editor-style', 'http://example.org/plugins/jetpack/mock-editor.css', array(), '1.0' ); | ||
| wp_register_script( 'disallowed-plugin-script', 'http://example.org/plugins/disallowed-plugin/script.js', array(), '1.0', true ); | ||
| wp_register_script( 'disallowed-plugin-style', 'http://example.org/plugins/disallowed-plugin/style.css', array(), '1.0', true ); | ||
|
|
||
| // Enqueue our mock assets | ||
| wp_enqueue_script( 'mock-editor-script' ); | ||
| wp_enqueue_style( 'mock-editor-style' ); | ||
| wp_enqueue_script( 'disallowed-plugin-script' ); | ||
| wp_enqueue_style( 'disallowed-plugin-style' ); | ||
|
Comment on lines
-46
to
-61
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Relocated these mocks to be co-located with related test cases to better communicate intent. |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -178,13 +151,30 @@ function ( $block_name ) { | |
| public function test_get_items_returns_allowed_plugin_assets() { | ||
| wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) ); | ||
|
|
||
| add_action( 'enqueue_block_editor_assets', array( $this, 'mock_allowed_plugin_assets' ) ); | ||
|
|
||
| $request = new WP_REST_Request( Requests::GET, '/wpcom/v2/editor-assets' ); | ||
| $response = $this->server->dispatch( $request ); | ||
| $data = $response->get_data(); | ||
|
|
||
| // Verify the allowed plugin script and style are in the output | ||
| $this->assertStringContainsString( 'mock-editor-script', $data['scripts'] ); | ||
| $this->assertStringContainsString( 'mock-editor-style', $data['styles'] ); | ||
| $this->assertStringContainsString( 'jetpack-mock-script', $data['scripts'] ); | ||
| $this->assertStringContainsString( 'jetpack-mock-style', $data['styles'] ); | ||
|
|
||
| remove_action( 'enqueue_block_editor_assets', array( $this, 'mock_allowed_plugin_assets' ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Enqueue allowed plugin assets. | ||
| */ | ||
| public function mock_allowed_plugin_assets() { | ||
| // Register minimal mock assets that don't require actual files | ||
| wp_register_script( 'jetpack-mock-script', 'http://example.org/mock-editor.js', array(), '1.0', true ); | ||
| wp_register_style( 'jetpack-mock-style', 'http://example.org/mock-editor.css', array(), '1.0' ); | ||
|
|
||
| // Enqueue our mock assets | ||
| wp_enqueue_script( 'jetpack-mock-script' ); | ||
| wp_enqueue_style( 'jetpack-mock-style' ); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -193,13 +183,28 @@ public function test_get_items_returns_allowed_plugin_assets() { | |
| public function test_disallowed_plugin_assets_are_filtered() { | ||
| wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) ); | ||
|
|
||
| add_action( 'enqueue_block_editor_assets', array( $this, 'mock_disallowed_plugin_assets' ) ); | ||
|
|
||
| $request = new WP_REST_Request( Requests::GET, '/wpcom/v2/editor-assets' ); | ||
| $response = $this->server->dispatch( $request ); | ||
| $data = $response->get_data(); | ||
|
|
||
| // Verify the disallowed plugin script and style are not in the output | ||
| $this->assertStringNotContainsString( 'disallowed-plugin-script', $data['scripts'] ); | ||
| $this->assertStringNotContainsString( 'disallowed-plugin-style', $data['styles'] ); | ||
|
|
||
| remove_action( 'enqueue_block_editor_assets', array( $this, 'mock_disallowed_plugin_assets' ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Enqueue disallowed plugin assets. | ||
| */ | ||
| public function mock_disallowed_plugin_assets() { | ||
| wp_register_script( 'disallowed-plugin-script', 'http://example.org/script.js', array(), '1.0', true ); | ||
| wp_register_style( 'disallowed-plugin-style', 'http://example.org/style.css', array(), '1.0' ); | ||
|
|
||
| wp_enqueue_script( 'disallowed-plugin-script' ); | ||
| wp_enqueue_style( 'disallowed-plugin-style' ); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -216,6 +221,38 @@ public function test_protected_handles_are_preserved() { | |
| $this->assertStringContainsString( 'jquery', $data['scripts'] ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that WPCOM-specific Gutenberg assets are preserved. | ||
| */ | ||
| public function test_wpcom_gutenberg_assets_are_preserved() { | ||
| wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) ); | ||
|
|
||
| add_action( 'enqueue_block_editor_assets', array( $this, 'mock_wpcom_gutenberg_assets' ) ); | ||
|
|
||
| $request = new WP_REST_Request( Requests::GET, '/wpcom/v2/editor-assets' ); | ||
| $response = $this->server->dispatch( $request ); | ||
| $data = $response->get_data(); | ||
|
|
||
| // Verify the WPCOM Gutenberg assets are preserved in the output | ||
| $this->assertStringContainsString( 'wpcom-gutenberg-script', $data['scripts'] ); | ||
| $this->assertStringContainsString( 'wpcom-gutenberg-style', $data['styles'] ); | ||
| $this->assertStringContainsString( 'plugins/gutenberg-core/script.js', $data['scripts'] ); | ||
| $this->assertStringContainsString( 'plugins/gutenberg-core/style.css', $data['styles'] ); | ||
|
|
||
| remove_action( 'enqueue_block_editor_assets', array( $this, 'mock_wpcom_gutenberg_assets' ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Enqueue assets using WPCOM's specific Gutenberg paths. | ||
| */ | ||
| public function mock_wpcom_gutenberg_assets() { | ||
| wp_register_script( 'wpcom-gutenberg-script', 'http://example.org/plugins/gutenberg-core/script.js', array(), '1.0', true ); | ||
| wp_register_style( 'wpcom-gutenberg-style', 'http://example.org/plugins/gutenberg-core/style.css', array(), '1.0' ); | ||
|
|
||
| wp_enqueue_script( 'wpcom-gutenberg-script' ); | ||
| wp_enqueue_style( 'wpcom-gutenberg-style' ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that required WordPress actions are triggered. | ||
| */ | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path-based allow list meant that inline script tags were erroneously disallowed, as inline scripts do not have a path assigned to a
srcattribute.