diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php
index 462ebaf1f4..dc4bf24648 100644
|
a
|
b
|
function wp_targeted_link_rel_callback( $matches ) {
|
| 3065 | 3065 | */ |
| 3066 | 3066 | $rel = apply_filters( 'wp_targeted_link_rel', 'noopener noreferrer', $link_html ); |
| 3067 | 3067 | |
| | 3068 | // Avoid additional regex if the filter removes rel values. |
| | 3069 | if ( ! $rel ) { |
| | 3070 | return "<a $link_html>"; |
| | 3071 | } |
| | 3072 | |
| 3068 | 3073 | // Value with delimiters, spaces around are optional. |
| 3069 | 3074 | $attr_regex = '|rel\s*=\s*?(\\\\{0,1}["\'])(.*?)\\1|i'; |
| 3070 | 3075 | preg_match( $attr_regex, $link_html, $rel_match ); |
diff --git a/tests/phpunit/tests/formatting/WPTargetedLinkRel.php b/tests/phpunit/tests/formatting/WPTargetedLinkRel.php
index 49c843ec2c..5693f02973 100644
|
a
|
b
|
class Tests_Targeted_Link_Rel extends WP_UnitTestCase {
|
| 71 | 71 | $expected = '<p>Links: <a href="/" target="_blank" rel="noopener noreferrer">Change me</a> <a href="/">Do not change me</a></p>'; |
| 72 | 72 | $this->assertEquals( $expected, wp_targeted_link_rel( $content ) ); |
| 73 | 73 | } |
| | 74 | |
| | 75 | /** |
| | 76 | * Ensure empty rel attributes are not added. |
| | 77 | * |
| | 78 | * @ticket 45352. |
| | 79 | */ |
| | 80 | public function test_ignore_if_wp_targeted_link_rel_nulled() { |
| | 81 | add_filter( 'wp_targeted_link_rel', '__return_empty_string' ); |
| | 82 | $content = '<p>Links: <a href="/" target="_blank">Do not change me</a></p>'; |
| | 83 | $expected = '<p>Links: <a href="/" target="_blank">Do not change me</a></p>'; |
| | 84 | $this->assertEquals( $expected, wp_targeted_link_rel( $content ) ); |
| | 85 | } |
| 74 | 86 | } |