From af07f6af4b074203cb2b37b0e2231a88fc76ca48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=83=C2=B3=C3=85=E2=80=9Akowski?= Date: Fri, 11 Feb 2022 12:12:56 +0000 Subject: [PATCH] I18n: Standardize the script paths for blocks When providing file paths to scripts (editorScript, script or viewScript), when there is a trailing ./ included then there was a different md5 generated for the file that didn't match the one used with the file generated in the translations folder. Props Rahe. See #54797. git-svn-id: https://develop.svn.wordpress.org/trunk@52699 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/blocks.php | 6 +++++- tests/phpunit/tests/blocks/register.php | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) 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 ); } /**