Ticket #9959: 9959.diff
File 9959.diff, 1.8 KB (added by , 9 years ago) |
---|
-
src/wp-includes/formatting.php
2259 2259 */ 2260 2260 function wp_rel_nofollow_callback( $matches ) { 2261 2261 $text = $matches[1]; 2262 $text = str_replace(array(' rel="nofollow"', " rel='nofollow'"), '', $text); 2263 return "<a $text rel=\"nofollow\">"; 2262 $atts = shortcode_parse_atts( $matches[1] ); 2263 $rel = 'nofollow'; 2264 if ( ! empty( $atts['rel'] ) ) { 2265 $parts = array_map( 'trim', explode( ' ', $atts['rel'] ) ); 2266 if ( false === array_search( 'nofollow', $parts ) ) { 2267 $parts[] = 'nofollow'; 2268 } 2269 $rel = implode( ' ', $parts ); 2270 unset( $atts['rel'] ); 2271 2272 $html = ''; 2273 foreach ( $atts as $name => $value ) { 2274 $html .= "{$name}=\"$value\" "; 2275 } 2276 $text = trim( $html ); 2277 } 2278 return "<a $text rel=\"$rel\">"; 2264 2279 } 2265 2280 2266 2281 /** -
tests/phpunit/tests/formatting/WPRelNoFollow.php
1 <?php 2 /** 3 * @ticket 9959 4 */ 5 class Tests_Rel_No_Follow extends WP_UnitTestCase { 6 7 public function test_add_no_follow() { 8 $content = '<p>This is some cool <a href="/">Code</a></p>'; 9 $expected = '<p>This is some cool <a href=\"/\" rel=\"nofollow\">Code</a></p>'; 10 $this->assertEquals( $expected, wp_rel_nofollow( $content ) ); 11 } 12 13 public function test_convert_no_follow() { 14 $content = '<p>This is some cool <a href="/" rel="weird">Code</a></p>'; 15 $expected = '<p>This is some cool <a href=\"/\" rel=\"weird nofollow\">Code</a></p>'; 16 $this->assertEquals( $expected, wp_rel_nofollow( $content ) ); 17 } 18 } 19 No newline at end of file