From d9dc716cff7285e20dad6cadc44b67046e875641 Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Tue, 30 Nov 2021 20:00:09 +0000 Subject: [PATCH] Editor: Avoid a JS console error on the Navigation block view. Props mkaz, sabernhardt, costdev. Fixes #54456. git-svn-id: https://develop.svn.wordpress.org/trunk@52291 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/blocks.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index f5b8b47e5e..ff087d0b82 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -83,9 +83,11 @@ function register_block_script_handle( $metadata, $field_name ) { } $script_handle = generate_block_asset_handle( $metadata['name'], $field_name ); - $script_asset_path = realpath( - dirname( $metadata['file'] ) . '/' . - substr_replace( $script_path, '.asset.php', - strlen( '.js' ) ) + $script_asset_path = wp_normalize_path( + realpath( + dirname( $metadata['file'] ) . '/' . + substr_replace( $script_path, '.asset.php', - strlen( '.js' ) ) + ) ); if ( ! file_exists( $script_asset_path ) ) { _doing_it_wrong( @@ -100,9 +102,13 @@ function register_block_script_handle( $metadata, $field_name ) { ); return false; } - $is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], ABSPATH . WPINC ); + // Path needs to be normalized to work in Windows env. + $wpinc_path_norm = wp_normalize_path( ABSPATH . WPINC ); + $script_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $script_path ) ); + $is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm ); + $script_uri = $is_core_block ? - includes_url( str_replace( ABSPATH . WPINC, '', realpath( dirname( $metadata['file'] ) . '/' . $script_path ) ) ) : + includes_url( str_replace( $wpinc_path_norm, '', $script_path_norm ) ) : plugins_url( $script_path, $metadata['file'] ); $script_asset = require $script_asset_path; $script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array(); @@ -139,7 +145,8 @@ function register_block_style_handle( $metadata, $field_name ) { if ( empty( $metadata[ $field_name ] ) ) { return false; } - $is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], ABSPATH . WPINC ); + $wpinc_path_norm = wp_normalize_path( ABSPATH . WPINC ); + $is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm ); if ( $is_core_block && ! wp_should_load_separate_core_block_assets() ) { return false; } @@ -232,7 +239,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) { if ( ! is_array( $metadata ) || empty( $metadata['name'] ) ) { return false; } - $metadata['file'] = $metadata_file; + $metadata['file'] = wp_normalize_path( $metadata_file ); /** * Filters the metadata provided for registering a block type.