Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation Block: Properly decode URL-encoded links #46435

Merged
2 changes: 1 addition & 1 deletion packages/block-library/src/navigation-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function render_block_core_navigation_link( $attributes, $content, $block ) {

// Start appending HTML attributes to anchor tag.
if ( isset( $attributes['url'] ) ) {
$html .= ' href="' . esc_url( $attributes['url'] ) . '"';
$html .= ' href="' . esc_url( urldecode( $attributes['url'] ) ) . '"';
}

if ( $is_active ) {
Expand Down
29 changes: 29 additions & 0 deletions phpunit/class-block-library-navigation-link-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,35 @@ public function test_returns_link_for_plain_link() {
);
}

public function test_returns_link_for_decoded_link() {
$parsed_blocks = parse_blocks(
'<!-- wp:navigation-link {"label":"My Website","url": "https://example.com/?data=lzB%252Fzd%252FZA%253D%253D"} /-->'
);
$this->assertEquals( 1, count( $parsed_blocks ) );

$navigation_link_block = new WP_Block( $parsed_blocks[0], array() );

echo(
render_block_core_navigation_link(
$navigation_link_block->attributes,
array(),
$navigation_link_block
)
);

$this->assertEquals(
true,
strpos(
render_block_core_navigation_link(
kozer marked this conversation as resolved.
Show resolved Hide resolved
$navigation_link_block->attributes,
array(),
$navigation_link_block
),
'https://example.com/?data=lzB%2Fzd%2FZA%3D%3D'
) !== false
);
}

public function test_returns_empty_when_custom_post_type_draft() {
$page_id = self::$custom_draft->ID;

Expand Down