diff --git src/wp-includes/formatting.php src/wp-includes/formatting.php
index 4fb4135..47f8e5f 100644
|
|
|
function wp_targeted_link_rel_callback( $matches ) { |
| 3168 | 3168 | preg_match( $attr_regex, $link_html, $rel_match ); |
| 3169 | 3169 | } |
| 3170 | 3170 | |
| 3171 | | if ( ! empty( $rel_match[0] ) ) { |
| | 3171 | if ( ! empty( $rel_match[0] ) && preg_match( '#(^\s*|\s+)rel\s*=#', $link_html ) ) { |
| 3172 | 3172 | $parts = preg_split( '|\s+|', strtolower( $rel_match[2] ) ); |
| 3173 | 3173 | $parts = array_map( 'esc_attr', $parts ); |
| 3174 | 3174 | $needed = explode( ' ', $rel ); |
diff --git tests/phpunit/tests/formatting/WPTargetedLinkRel.php tests/phpunit/tests/formatting/WPTargetedLinkRel.php
index 8be254a..9a12df8 100644
|
|
|
class Tests_Targeted_Link_Rel extends WP_UnitTestCase { |
| 139 | 139 | $this->assertEquals( $expected, wp_targeted_link_rel( $content ) ); |
| 140 | 140 | } |
| 141 | 141 | |
| | 142 | /** |
| | 143 | * Ensure rel parameter in href is ignored when no rel attribute. |
| | 144 | * |
| | 145 | * @ticket 48261 |
| | 146 | */ |
| | 147 | public function test_ignore_rel_param_in_href_when_no_rel_attribute() { |
| | 148 | $content = '<a href="https://www.somesite.com/index.php?v=yes&rel=0" target="_blank">Anchor Text</a>'; |
| | 149 | $expected = '<a href="https://www.somesite.com/index.php?v=yes&rel=0" target="_blank" rel="noopener noreferrer">Anchor Text</a>'; |
| | 150 | $this->assertEquals( $expected, wp_targeted_link_rel( $content ) ); |
| | 151 | } |
| | 152 | |
| | 153 | /** |
| | 154 | * Ensure rel parameter in href is ignored when rel attribute exists. |
| | 155 | * |
| | 156 | * @ticket 48261 |
| | 157 | */ |
| | 158 | public function test_ignore_rel_param_in_href_when_rel_attribute() { |
| | 159 | $content = '<a href="https://www.somesite.com/index.php?v=yes&rel=0" rel="noopener noreferrer" target="_blank">Anchor Text</a>'; |
| | 160 | $expected = '<a href="https://www.somesite.com/index.php?v=yes&rel=0" rel="noopener noreferrer" target="_blank">Anchor Text</a>'; |
| | 161 | $this->assertEquals( $expected, wp_targeted_link_rel( $content ) ); |
| | 162 | } |
| | 163 | |
| | 164 | /** |
| | 165 | * Ensure rel parameter in href is ignored when rel is the first attribute. |
| | 166 | * |
| | 167 | * @ticket 48261 |
| | 168 | */ |
| | 169 | public function test_ignore_rel_param_in_href_when_rel_first_attribute() { |
| | 170 | $content = '<a rel="test" href="https://www.somesite.com/index.php?v=yes&rel=0" target="_blank">Anchor Text</a>'; |
| | 171 | $expected = '<a rel="test noopener noreferrer" href="https://www.somesite.com/index.php?v=yes&rel=0" target="_blank">Anchor Text</a>'; |
| | 172 | $this->assertEquals( $expected, wp_targeted_link_rel( $content ) ); |
| | 173 | } |
| | 174 | |
| 142 | 175 | } |