diff --git a/packages/block-library/src/navigation-link/index.php b/packages/block-library/src/navigation-link/index.php index 71ef26b630d51..749bae7aec64e 100644 --- a/packages/block-library/src/navigation-link/index.php +++ b/packages/block-library/src/navigation-link/index.php @@ -132,6 +132,10 @@ function block_core_navigation_link_maybe_urldecode( $url ) { $query_params = wp_parse_args( $query ); foreach ( $query_params as $query_param ) { + $can_query_param_be_encoded = is_string( $query_param ) && ! empty( $query_param ); + if ( ! $can_query_param_be_encoded ) { + continue; + } if ( rawurldecode( $query_param ) !== $query_param ) { $is_url_encoded = true; break; diff --git a/phpunit/class-block-library-navigation-link-test.php b/phpunit/class-block-library-navigation-link-test.php index 7223a7d45abda..993f93fb8cad0 100644 --- a/phpunit/class-block-library-navigation-link-test.php +++ b/phpunit/class-block-library-navigation-link-test.php @@ -222,12 +222,14 @@ public function test_returns_link_for_decoded_link() { 'https://example.com/?id=10&data=lzB%252Fzd%252FZA%253D%253D', 'https://example.com/?id=10&data=lzB%2Fzd%FZA%3D%3D', 'https://example.com/?id=10&data=1234', + 'https://example.com/?arrayParams[]=1&arrayParams[]=2&arrayParams[]=3', ); $urls_after_render = array( 'https://example.com/?id=10&data=lzB%2Fzd%2FZA%3D%3D', 'https://example.com/?id=10&data=lzB%2Fzd%FZA%3D%3D', 'https://example.com/?id=10&data=1234', + 'https://example.com/?arrayParams%5B%5D=1&arrayParams%5B%5D=2&arrayParams%5B%5D=3', ); foreach ( $urls_before_render as $idx => $link ) {