diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 28e269c1d9..cec2f36925 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -20,10 +20,14 @@ function remove_block_asset_path_prefix( $asset_handle_or_path ) { if ( 0 !== strpos( $asset_handle_or_path, $path_prefix ) ) { return $asset_handle_or_path; } - return substr( + $path = substr( $asset_handle_or_path, strlen( $path_prefix ) ); + if ( strpos( $path, './' ) === 0 ) { + $path = substr( $path, 2 ); + } + return $path; } /** diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index 07800a98a3..542fe3c726 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -122,9 +122,18 @@ class Tests_Blocks_Register extends WP_UnitTestCase { * @ticket 50263 */ public function test_removes_block_asset_path_prefix() { + $result = remove_block_asset_path_prefix( 'file:block.js' ); + + $this->assertSame( 'block.js', $result ); + } + + /** + * @ticket 54797 + */ + public function test_removes_block_asset_path_prefix_and_current_directory() { $result = remove_block_asset_path_prefix( 'file:./block.js' ); - $this->assertSame( './block.js', $result ); + $this->assertSame( 'block.js', $result ); } /**