Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/wp-includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -3279,8 +3279,8 @@ function make_clickable( $text ) {
}
}

// Cleanup of accidental links within links.
return preg_replace( '#(<a([ \r\n\t]+[^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i', '$1$3</a>', $r );
// Cleanup of accidental links within links, keeping any text around the nested link.
return preg_replace( '#(<a([ \r\n\t]+[^>]+?>|>))([^<]*)<a [^>]+?>([^>]+?)</a>([^<]*)</a>#i', '$1$3$4$5</a>', $r );
}

/**
Expand Down
29 changes: 29 additions & 0 deletions tests/phpunit/tests/formatting/makeClickable.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,35 @@ public function test_line_break_in_existing_clickable_link() {
$this->assertSame( $html, make_clickable( $html ) );
}

/**
* Tests that a URL inside an existing link is not linked a second time.
*
* @ticket 50514
* @dataProvider data_url_inside_existing_link
*
* @param string $html Content that already contains a link.
*/
public function test_url_inside_existing_link_is_not_nested( $html ) {
$this->assertSame( $html, make_clickable( $html ) );
}

/**
* Data provider.
*
* @return array[]
*/
public static function data_url_inside_existing_link() {
return array(
'link text is only the URL' => array( '<a href="https://w.org">https://w.org</a>' ),
'space before the URL' => array( '<a href="https://w.org"> https://w.org</a>' ),
'space after the URL' => array( '<a href="https://w.org">https://w.org </a>' ),
'text before and after the URL' => array( '<a href="https://w.org">Visit https://w.org now</a>' ),
'newline before the URL' => array( "<a href=\"https://w.org\">\nhttps://w.org</a>" ),
'two adjacent links' => array( '<a href="http://example.com/">http://example.com/</a><a href="http://example.com/">http://example.com/</a>' ),
'two links separated by text' => array( '<a href="http://example.com/a">http://example.com/a</a> and <a href="http://example.com/b">http://example.com/b</a>' ),
);
}

/**
* @ticket 30162
* @dataProvider data_script_and_style_tags
Expand Down
Loading