Skip to content

Commit

Permalink
Fix url escaping for array parameters in Navigation links (#58068)
Browse files Browse the repository at this point in the history
* fix escaping URLs in navigation links

* add test case

* undo the class suffix remove in test setup
  • Loading branch information
draganescu authored Jan 31, 2024
1 parent 46fec08 commit eab51ec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/block-library/src/navigation-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions phpunit/class-block-library-navigation-link-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down

0 comments on commit eab51ec

Please sign in to comment.