Changeset 55289
- Timestamp:
- 02/07/2023 06:52:24 PM (21 months ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/package.json
r55275 r55289 177 177 "env:logs": "node ./tools/local-env/scripts/docker.js logs", 178 178 "env:pull": "node ./tools/local-env/scripts/docker.js pull", 179 "test:php": "node ./tools/local-env/scripts/docker.js run -T php composer update -W && node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit ",179 "test:php": "node ./tools/local-env/scripts/docker.js run -T php composer update -W && node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit --group formatting", 180 180 "test:e2e": "node ./tests/e2e/run-tests.js", 181 181 "test:visual": "node ./tests/visual-regression/run-tests.js", -
trunk/src/wp-includes/comment-template.php
r55287 r55289 219 219 */ 220 220 function get_comment_author_link( $comment_ID = 0 ) { 221 $comment = get_comment( $comment_ID ); 222 $url = get_comment_author_url( $comment ); 223 $author = get_comment_author( $comment ); 221 $comment = get_comment( $comment_ID ); 222 $comment_ID = ! empty( $comment->comment_ID ) ? $comment->comment_ID : (string) $comment_ID; 223 $url = get_comment_author_url( $comment ); 224 $author = get_comment_author( $comment ); 224 225 225 226 if ( empty( $url ) || 'http://' === $url ) { 226 227 $return = $author; 227 228 } else { 228 $return = "<a href='$url' rel='external nofollow ugc' class='url'>$author</a>"; 229 $rel_parts = array( 'ugc' ); 230 if ( ! wp_is_internal_link( $url ) ) { 231 $rel_parts = array_merge( 232 $rel_parts, 233 array( 'external', 'nofollow' ) 234 ); 235 } 236 237 /** 238 * Filters the rel attributes of the comment author's link. 239 * 240 * @since 6.2.0 241 * 242 * @param string[] $rel_parts An array of strings representing the rel 243 * tags which will be joined into the anchor's 244 * rel attribute. 245 * @param WP_Comment $comment The comment object 246 */ 247 $rel_parts = apply_filters( 'comment_author_link_rel', $rel_parts, $comment ); 248 249 $rel = implode( ' ', $rel_parts ); 250 $rel = esc_attr( $rel ); 251 // empty space before rel necessary for later sprintf. 252 $rel = ! empty( $rel ) ? sprintf( ' rel="%s"', $rel ) : ''; 253 254 $return = sprintf( 255 '<a href="%1$s" class="url"%2$s>%3$s</a>', 256 $url, 257 $rel, 258 $author 259 ); 229 260 } 230 261 … … 240 271 * @param string $comment_ID The comment ID as a numeric string. 241 272 */ 242 return apply_filters( 'get_comment_author_link', $return, $author, $comment ->comment_ID );273 return apply_filters( 'get_comment_author_link', $return, $author, $comment_ID ); 243 274 } 244 275 -
trunk/src/wp-includes/formatting.php
r55279 r55289 2918 2918 } 2919 2919 2920 if ( 'comment_text' === current_filter() ) { 2921 $rel = 'nofollow ugc'; 2922 } else { 2923 $rel = 'nofollow'; 2924 } 2925 2926 /** 2927 * Filters the rel value that is added to URL matches converted to links. 2928 * 2929 * @since 5.3.0 2930 * 2931 * @param string $rel The rel value. 2932 * @param string $url The matched URL being converted to a link tag. 2933 */ 2934 $rel = apply_filters( 'make_clickable_rel', $rel, $url ); 2935 $rel = esc_attr( $rel ); 2936 2937 return $matches[1] . "<a href=\"$url\" rel=\"$rel\">$url</a>" . $suffix; 2920 $rel_attr = _make_clickable_rel_attr( $url ); 2921 return $matches[1] . "<a href=\"$url\"$rel_attr>$url</a>" . $suffix; 2922 2938 2923 } 2939 2924 … … 2966 2951 } 2967 2952 2968 if ( 'comment_text' === current_filter() ) { 2969 $rel = 'nofollow ugc'; 2970 } else { 2971 $rel = 'nofollow'; 2972 } 2973 2974 /** This filter is documented in wp-includes/formatting.php */ 2975 $rel = apply_filters( 'make_clickable_rel', $rel, $dest ); 2976 $rel = esc_attr( $rel ); 2977 2978 return $matches[1] . "<a href=\"$dest\" rel=\"$rel\">$dest</a>$ret"; 2953 $rel_attr = _make_clickable_rel_attr( $dest ); 2954 return $matches[1] . "<a href='{$dest}'{$rel_attr}>{$dest}</a>{$ret}"; 2979 2955 } 2980 2956 … … 2993 2969 $email = $matches[2] . '@' . $matches[3]; 2994 2970 return $matches[1] . "<a href=\"mailto:$email\">$email</a>"; 2971 } 2972 2973 /** 2974 * Helper function used to build the "rel" attribute for a URL when creating an anchor using make_clickable(). 2975 * 2976 * @since 6.2.0 2977 * 2978 * @param string $url The URL. 2979 * @return string The rel attribute for the anchor or an empty string if no rel attribute should be added. 2980 */ 2981 function _make_clickable_rel_attr( $url ) { 2982 2983 $rel_parts = array(); 2984 $scheme = strtolower( wp_parse_url( $url, PHP_URL_SCHEME ) ); 2985 $nofollow_schemes = array_intersect( wp_allowed_protocols(), array( 'https', 'http' ) ); 2986 2987 // Apply "nofollow" to external links with qualifying URL schemes (mailto:, tel:, etc... shouldn't be followed). 2988 if ( ! wp_is_internal_link( $url ) && in_array( $scheme, $nofollow_schemes, true ) ) { 2989 $rel_parts[] = 'nofollow'; 2990 } 2991 2992 // Apply "ugc" when in comment context. 2993 if ( 'comment_text' === current_filter() ) { 2994 $rel_parts[] = 'ugc'; 2995 } 2996 2997 $rel = implode( ' ', $rel_parts ); 2998 2999 /** 3000 * Filters the rel value that is added to URL matches converted to links. 3001 * 3002 * @since 5.3.0 3003 * 3004 * @param string $rel The rel value. 3005 * @param string $url The matched URL being converted to a link tag. 3006 */ 3007 $rel = apply_filters( 'make_clickable_rel', $rel, $url ); 3008 3009 $rel_attr = $rel ? ' rel="' . esc_attr( $rel ) . '"' : ''; 3010 3011 return $rel_attr; 3012 2995 3013 } 2996 3014 … … 3138 3156 $atts = wp_kses_hair( $matches[1], wp_allowed_protocols() ); 3139 3157 3140 if ( ! empty( $atts['href'] ) ) { 3141 if ( in_array( strtolower( wp_parse_url( $atts['href']['value'], PHP_URL_SCHEME ) ), array( 'http', 'https' ), true ) ) { 3142 if ( strtolower( wp_parse_url( $atts['href']['value'], PHP_URL_HOST ) ) === strtolower( wp_parse_url( home_url(), PHP_URL_HOST ) ) ) { 3143 return "<a $text>"; 3144 } 3145 } 3158 if ( ! empty( $atts['href'] ) && wp_is_internal_link( $atts['href']['value'] ) ) { 3159 $rel = trim( str_replace( 'nofollow', '', $rel ) ); 3146 3160 } 3147 3161 … … 3163 3177 $text = trim( $html ); 3164 3178 } 3165 return "<a $text rel=\"" . esc_attr( $rel ) . '">'; 3179 3180 $rel_attr = $rel ? ' rel="' . esc_attr( $rel ) . '"' : ''; 3181 3182 return "<a {$text}{$rel_attr}>"; 3166 3183 } 3167 3184 -
trunk/src/wp-includes/link-template.php
r55276 r55289 4689 4689 return ''; 4690 4690 } 4691 4692 /** 4693 * Returns an array of URL hosts which are considered to be internal hosts. 4694 * 4695 * By default the list of internal hosts is comproside of the PHP_URL_HOST of 4696 * the site's home_url() (as parsed by wp_parse_url()). 4697 * 4698 * This list is used when determining if a specificed URL is a link to a page on 4699 * the site itself or a link offsite (to an external host). This is used, for 4700 * example, when determining if the "nofollow" attribute should be applied to a 4701 * link. 4702 * 4703 * @see wp_is_internal_link 4704 * 4705 * @since 6.2.0 4706 * 4707 * @return string[] An array of URL hosts. 4708 */ 4709 function wp_internal_hosts() { 4710 static $internal_hosts; 4711 4712 if ( empty( $internal_hosts ) ) { 4713 /** 4714 * Filters the array of URL hosts which are considered internal. 4715 * 4716 * @since 6.2.9 4717 * 4718 * @param array $internal_hosts An array of internal URL hostnames. 4719 */ 4720 $internal_hosts = apply_filters( 4721 'wp_internal_hosts', 4722 array( 4723 wp_parse_url( home_url(), PHP_URL_HOST ), 4724 ) 4725 ); 4726 $internal_hosts = array_unique( 4727 array_map( 'strtolower', (array) $internal_hosts ) 4728 ); 4729 } 4730 4731 return $internal_hosts; 4732 } 4733 4734 /** 4735 * Determines whether or not the specified URL is of a host included in the internal hosts list. 4736 * 4737 * @see wp_internal_hosts() 4738 * 4739 * @since 6.2.0 4740 * 4741 * @param string $link The URL to test. 4742 * @return bool Returns true for internal URLs and false for all other URLs. 4743 */ 4744 function wp_is_internal_link( $link ) { 4745 $link = strtolower( $link ); 4746 if ( in_array( wp_parse_url( $link, PHP_URL_SCHEME ), wp_allowed_protocols(), true ) ) { 4747 return in_array( wp_parse_url( $link, PHP_URL_HOST ), wp_internal_hosts(), true ); 4748 } 4749 return false; 4750 } -
trunk/tests/phpunit/tests/formatting/makeClickable.php
r53562 r55289 109 109 ); 110 110 $urls_expected = array( 111 '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>',112 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>. Alice!',113 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>, said Alice.',114 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>; said Alice.',115 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>: said Alice.',116 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>) said Alice.',111 "<a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>", 112 "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>. Alice!", 113 "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>, said Alice.", 114 "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>; said Alice.", 115 "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>: said Alice.", 116 "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>) said Alice.", 117 117 ); 118 118 … … 136 136 ); 137 137 $urls_expected = array( 138 '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>',139 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>.',140 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>,',141 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>;',142 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>:',143 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>)',138 "<a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>", 139 "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>.", 140 "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>,", 141 "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>;", 142 "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>:", 143 "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>)", 144 144 ); 145 145 … … 218 218 ); 219 219 $urls_expected = array( 220 'Example: WordPress, test (some text), I love example.com (<a href="http://example.org" rel="nofollow">http://example.org</a>), it is brilliant',220 'Example: WordPress, test (some text), I love example.com (<a href="http://example.org">http://example.org</a>), it is brilliant', 221 221 'Example: WordPress, test (some text), I love example.com (<a href="http://example.com" rel="nofollow">http://example.com</a>), it is brilliant', 222 222 'Some text followed by a bracketed link with a trailing elipsis (<a href="http://example.com" rel="nofollow">http://example.com</a>)...', … … 422 422 /** 423 423 * @ticket 48022 424 * @ticket 56444 424 425 * @dataProvider data_add_rel_ugc_in_comments 425 426 */ … … 439 440 440 441 public function data_add_rel_ugc_in_comments() { 442 443 $home_url_http = set_url_scheme( home_url(), 'http' ); 444 $home_url_https = set_url_scheme( home_url(), 'https' ); 445 441 446 return array( 447 // @ticket 48022 442 448 array( 443 449 'http://wordpress.org', … … 446 452 array( 447 453 'www.wordpress.org', 448 '<p><a href="http://www.wordpress.org" rel="nofollow ugc">http://www.wordpress.org</a>', 454 '<p><a href=\'http://www.wordpress.org\' rel="nofollow ugc">http://www.wordpress.org</a>', 455 ), 456 // @ticket 56444 457 array( 458 'www.example.org', 459 '<p><a href=\'http://www.example.org\' rel="nofollow ugc">http://www.example.org</a>', 460 ), 461 array( 462 $home_url_http, 463 '<a href="' . $home_url_http . '" rel="ugc">' . $home_url_http . '</a>', 464 ), 465 array( 466 $home_url_https, 467 '<a href="' . $home_url_https . '" rel="ugc">' . $home_url_https . '</a>', 449 468 ), 450 469 ); -
trunk/tests/phpunit/tests/formatting/wpRelNofollow.php
r53562 r55289 12 12 */ 13 13 public function test_add_no_follow() { 14 if ( PHP_VERSION_ID >= 80100 ) {15 /*16 * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in17 * via hooked in filter functions until a more structural solution to the18 * "missing input validation" conundrum has been architected and implemented.19 */20 $this->expectDeprecation();21 $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );22 }23 24 14 $content = '<p>This is some cool <a href="/">Code</a></p>'; 25 15 $expected = '<p>This is some cool <a href=\"/\" rel=\"nofollow\">Code</a></p>'; … … 31 21 */ 32 22 public function test_convert_no_follow() { 33 if ( PHP_VERSION_ID >= 80100 ) {34 /*35 * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in36 * via hooked in filter functions until a more structural solution to the37 * "missing input validation" conundrum has been architected and implemented.38 */39 $this->expectDeprecation();40 $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );41 }42 43 23 $content = '<p>This is some cool <a href="/" rel="weird">Code</a></p>'; 44 24 $expected = '<p>This is some cool <a href=\"/\" rel=\"weird nofollow\">Code</a></p>'; … … 51 31 */ 52 32 public function test_wp_rel_nofollow( $input, $output, $expect_deprecation = false ) { 53 if ( true === $expect_deprecation && PHP_VERSION_ID >= 80100 ) {54 /*55 * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in56 * via hooked in filter functions until a more structural solution to the57 * "missing input validation" conundrum has been architected and implemented.58 */59 $this->expectDeprecation();60 $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );61 }62 63 33 $this->assertSame( wp_slash( $output ), wp_rel_nofollow( $input ) ); 64 34 } … … 110 80 111 81 public function test_append_no_follow_with_valueless_attribute() { 112 if ( PHP_VERSION_ID >= 80100 ) {113 /*114 * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in115 * via hooked in filter functions until a more structural solution to the116 * "missing input validation" conundrum has been architected and implemented.117 */118 $this->expectDeprecation();119 $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );120 }121 122 82 $content = '<p>This is some cool <a href="demo.com" download rel="hola">Code</a></p>'; 123 83 $expected = '<p>This is some cool <a href=\"demo.com\" download rel=\"hola nofollow\">Code</a></p>'; -
trunk/tests/phpunit/tests/formatting/wpRelUgc.php
r53562 r55289 12 12 */ 13 13 public function test_add_ugc() { 14 if ( PHP_VERSION_ID >= 80100 ) {15 /*16 * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in17 * via hooked in filter functions until a more structural solution to the18 * "missing input validation" conundrum has been architected and implemented.19 */20 $this->expectDeprecation();21 $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );22 }23 24 14 $content = '<p>This is some cool <a href="/">Code</a></p>'; 25 15 $expected = '<p>This is some cool <a href=\"/\" rel=\"nofollow ugc\">Code</a></p>'; … … 31 21 */ 32 22 public function test_convert_ugc() { 33 if ( PHP_VERSION_ID >= 80100 ) {34 /*35 * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in36 * via hooked in filter functions until a more structural solution to the37 * "missing input validation" conundrum has been architected and implemented.38 */39 $this->expectDeprecation();40 $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );41 }42 43 23 $content = '<p>This is some cool <a href="/" rel="weird">Code</a></p>'; 44 24 $expected = '<p>This is some cool <a href=\"/\" rel=\"weird nofollow ugc\">Code</a></p>'; … … 51 31 */ 52 32 public function test_wp_rel_ugc( $input, $output, $expect_deprecation = false ) { 53 if ( true === $expect_deprecation && PHP_VERSION_ID >= 80100 ) {54 /*55 * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in56 * via hooked in filter functions until a more structural solution to the57 * "missing input validation" conundrum has been architected and implemented.58 */59 $this->expectDeprecation();60 $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );61 }62 63 33 $this->assertSame( wp_slash( $output ), wp_rel_ugc( $input ) ); 64 34 } … … 100 70 array( 101 71 '<a href="' . $home_url_http . '/some-url">Home URL (http)</a>', 102 '<a href="' . $home_url_http . '/some-url" >Home URL (http)</a>',72 '<a href="' . $home_url_http . '/some-url" rel="ugc">Home URL (http)</a>', 103 73 ), 104 74 array( 105 75 '<a href="' . $home_url_https . '/some-url">Home URL (https)</a>', 106 '<a href="' . $home_url_https . '/some-url" >Home URL (https)</a>',76 '<a href="' . $home_url_https . '/some-url" rel="ugc">Home URL (https)</a>', 107 77 ), 108 78 ); … … 110 80 111 81 public function test_append_ugc_with_valueless_attribute() { 112 if ( PHP_VERSION_ID >= 80100 ) {113 /*114 * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in115 * via hooked in filter functions until a more structural solution to the116 * "missing input validation" conundrum has been architected and implemented.117 */118 $this->expectDeprecation();119 $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );120 }121 82 122 83 $content = '<p>This is some cool <a href="demo.com" download rel="hola">Code</a></p>';
Note: See TracChangeset
for help on using the changeset viewer.