<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[55289] trunk: Comments: Improve rel attribute usage in comments.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/55289">55289</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/55289","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>jorbin</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-02-07 18:52:24 +0000 (Tue, 07 Feb 2023)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Comments: Improve rel attribute usage in comments.
Internal links should be followed and it should be easier to modify other rel attributes on comments. This adds a helper function for determining if a URL is internal and also adds some new filters to make it easy to modify rel attributes in comments.
Props thomasplevy, desrosj, sabernhardt, benish74, samiamnot, galbaras, jorbin.
Fixes <a href="https://core.trac.wordpress.org/ticket/53290">#53290</a>, <a href="https://core.trac.wordpress.org/ticket/56444">#56444</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkpackagejson">trunk/package.json</a></li>
<li><a href="#trunksrcwpincludescommenttemplatephp">trunk/src/wp-includes/comment-template.php</a></li>
<li><a href="#trunksrcwpincludesformattingphp">trunk/src/wp-includes/formatting.php</a></li>
<li><a href="#trunksrcwpincludeslinktemplatephp">trunk/src/wp-includes/link-template.php</a></li>
<li><a href="#trunktestsphpunittestsformattingmakeClickablephp">trunk/tests/phpunit/tests/formatting/makeClickable.php</a></li>
<li><a href="#trunktestsphpunittestsformattingwpRelNofollowphp">trunk/tests/phpunit/tests/formatting/wpRelNofollow.php</a></li>
<li><a href="#trunktestsphpunittestsformattingwpRelUgcphp">trunk/tests/phpunit/tests/formatting/wpRelUgc.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkpackagejson"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/package.json</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/package.json 2023-02-07 18:50:01 UTC (rev 55288)
+++ trunk/package.json 2023-02-07 18:52:24 UTC (rev 55289)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -176,7 +176,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> "env:cli": "node ./tools/local-env/scripts/docker.js run cli",
</span><span class="cx" style="display: block; padding: 0 10px"> "env:logs": "node ./tools/local-env/scripts/docker.js logs",
</span><span class="cx" style="display: block; padding: 0 10px"> "env:pull": "node ./tools/local-env/scripts/docker.js pull",
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- "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",
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "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",
</ins><span class="cx" style="display: block; padding: 0 10px"> "test:e2e": "node ./tests/e2e/run-tests.js",
</span><span class="cx" style="display: block; padding: 0 10px"> "test:visual": "node ./tests/visual-regression/run-tests.js",
</span><span class="cx" style="display: block; padding: 0 10px"> "sync-gutenberg-packages": "grunt sync-gutenberg-packages",
</span></span></pre></div>
<a id="trunksrcwpincludescommenttemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/comment-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/comment-template.php 2023-02-07 18:50:01 UTC (rev 55288)
+++ trunk/src/wp-includes/comment-template.php 2023-02-07 18:52:24 UTC (rev 55289)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -218,14 +218,45 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string The comment author name or HTML link for author's URL.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function get_comment_author_link( $comment_ID = 0 ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment = get_comment( $comment_ID );
- $url = get_comment_author_url( $comment );
- $author = get_comment_author( $comment );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $comment = get_comment( $comment_ID );
+ $comment_ID = ! empty( $comment->comment_ID ) ? $comment->comment_ID : (string) $comment_ID;
+ $url = get_comment_author_url( $comment );
+ $author = get_comment_author( $comment );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $url ) || 'http://' === $url ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $return = $author;
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $return = "<a href='$url' rel='external nofollow ugc' class='url'>$author</a>";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $rel_parts = array( 'ugc' );
+ if ( ! wp_is_internal_link( $url ) ) {
+ $rel_parts = array_merge(
+ $rel_parts,
+ array( 'external', 'nofollow' )
+ );
+ }
+
+ /**
+ * Filters the rel attributes of the comment author's link.
+ *
+ * @since 6.2.0
+ *
+ * @param string[] $rel_parts An array of strings representing the rel
+ * tags which will be joined into the anchor's
+ * rel attribute.
+ * @param WP_Comment $comment The comment object
+ */
+ $rel_parts = apply_filters( 'comment_author_link_rel', $rel_parts, $comment );
+
+ $rel = implode( ' ', $rel_parts );
+ $rel = esc_attr( $rel );
+ // empty space before rel necessary for later sprintf.
+ $rel = ! empty( $rel ) ? sprintf( ' rel="%s"', $rel ) : '';
+
+ $return = sprintf(
+ '<a href="%1$s" class="url"%2$s>%3$s</a>',
+ $url,
+ $rel,
+ $author
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -239,7 +270,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $author The comment author's username.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $comment_ID The comment ID as a numeric string.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return apply_filters( 'get_comment_author_link', $return, $author, $comment->comment_ID );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return apply_filters( 'get_comment_author_link', $return, $author, $comment_ID );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="trunksrcwpincludesformattingphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/formatting.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/formatting.php 2023-02-07 18:50:01 UTC (rev 55288)
+++ trunk/src/wp-includes/formatting.php 2023-02-07 18:52:24 UTC (rev 55289)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2917,24 +2917,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $matches[0];
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( 'comment_text' === current_filter() ) {
- $rel = 'nofollow ugc';
- } else {
- $rel = 'nofollow';
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $rel_attr = _make_clickable_rel_attr( $url );
+ return $matches[1] . "<a href=\"$url\"$rel_attr>$url</a>" . $suffix;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * Filters the rel value that is added to URL matches converted to links.
- *
- * @since 5.3.0
- *
- * @param string $rel The rel value.
- * @param string $url The matched URL being converted to a link tag.
- */
- $rel = apply_filters( 'make_clickable_rel', $rel, $url );
- $rel = esc_attr( $rel );
-
- return $matches[1] . "<a href=\"$url\" rel=\"$rel\">$url</a>" . $suffix;
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2965,17 +2950,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $matches[0];
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( 'comment_text' === current_filter() ) {
- $rel = 'nofollow ugc';
- } else {
- $rel = 'nofollow';
- }
-
- /** This filter is documented in wp-includes/formatting.php */
- $rel = apply_filters( 'make_clickable_rel', $rel, $dest );
- $rel = esc_attr( $rel );
-
- return $matches[1] . "<a href=\"$dest\" rel=\"$rel\">$dest</a>$ret";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $rel_attr = _make_clickable_rel_attr( $dest );
+ return $matches[1] . "<a href='{$dest}'{$rel_attr}>{$dest}</a>{$ret}";
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2995,6 +2971,48 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Helper function used to build the "rel" attribute for a URL when creating an anchor using make_clickable().
+ *
+ * @since 6.2.0
+ *
+ * @param string $url The URL.
+ * @return string The rel attribute for the anchor or an empty string if no rel attribute should be added.
+ */
+function _make_clickable_rel_attr( $url ) {
+
+ $rel_parts = array();
+ $scheme = strtolower( wp_parse_url( $url, PHP_URL_SCHEME ) );
+ $nofollow_schemes = array_intersect( wp_allowed_protocols(), array( 'https', 'http' ) );
+
+ // Apply "nofollow" to external links with qualifying URL schemes (mailto:, tel:, etc... shouldn't be followed).
+ if ( ! wp_is_internal_link( $url ) && in_array( $scheme, $nofollow_schemes, true ) ) {
+ $rel_parts[] = 'nofollow';
+ }
+
+ // Apply "ugc" when in comment context.
+ if ( 'comment_text' === current_filter() ) {
+ $rel_parts[] = 'ugc';
+ }
+
+ $rel = implode( ' ', $rel_parts );
+
+ /**
+ * Filters the rel value that is added to URL matches converted to links.
+ *
+ * @since 5.3.0
+ *
+ * @param string $rel The rel value.
+ * @param string $url The matched URL being converted to a link tag.
+ */
+ $rel = apply_filters( 'make_clickable_rel', $rel, $url );
+
+ $rel_attr = $rel ? ' rel="' . esc_attr( $rel ) . '"' : '';
+
+ return $rel_attr;
+
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Converts plaintext URI to HTML links.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * Converts URI, www and ftp, and email addresses. Finishes by fixing links
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3137,12 +3155,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $text = $matches[1];
</span><span class="cx" style="display: block; padding: 0 10px"> $atts = wp_kses_hair( $matches[1], wp_allowed_protocols() );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! empty( $atts['href'] ) ) {
- if ( in_array( strtolower( wp_parse_url( $atts['href']['value'], PHP_URL_SCHEME ) ), array( 'http', 'https' ), true ) ) {
- if ( strtolower( wp_parse_url( $atts['href']['value'], PHP_URL_HOST ) ) === strtolower( wp_parse_url( home_url(), PHP_URL_HOST ) ) ) {
- return "<a $text>";
- }
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $atts['href'] ) && wp_is_internal_link( $atts['href']['value'] ) ) {
+ $rel = trim( str_replace( 'nofollow', '', $rel ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $atts['rel'] ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3162,7 +3176,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $text = trim( $html );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return "<a $text rel=\"" . esc_attr( $rel ) . '">';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $rel_attr = $rel ? ' rel="' . esc_attr( $rel ) . '"' : '';
+
+ return "<a {$text}{$rel_attr}>";
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="trunksrcwpincludeslinktemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/link-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/link-template.php 2023-02-07 18:50:01 UTC (rev 55288)
+++ trunk/src/wp-includes/link-template.php 2023-02-07 18:52:24 UTC (rev 55289)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4688,3 +4688,63 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return '';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Returns an array of URL hosts which are considered to be internal hosts.
+ *
+ * By default the list of internal hosts is comproside of the PHP_URL_HOST of
+ * the site's home_url() (as parsed by wp_parse_url()).
+ *
+ * This list is used when determining if a specificed URL is a link to a page on
+ * the site itself or a link offsite (to an external host). This is used, for
+ * example, when determining if the "nofollow" attribute should be applied to a
+ * link.
+ *
+ * @see wp_is_internal_link
+ *
+ * @since 6.2.0
+ *
+ * @return string[] An array of URL hosts.
+ */
+function wp_internal_hosts() {
+ static $internal_hosts;
+
+ if ( empty( $internal_hosts ) ) {
+ /**
+ * Filters the array of URL hosts which are considered internal.
+ *
+ * @since 6.2.9
+ *
+ * @param array $internal_hosts An array of internal URL hostnames.
+ */
+ $internal_hosts = apply_filters(
+ 'wp_internal_hosts',
+ array(
+ wp_parse_url( home_url(), PHP_URL_HOST ),
+ )
+ );
+ $internal_hosts = array_unique(
+ array_map( 'strtolower', (array) $internal_hosts )
+ );
+ }
+
+ return $internal_hosts;
+}
+
+/**
+ * Determines whether or not the specified URL is of a host included in the internal hosts list.
+ *
+ * @see wp_internal_hosts()
+ *
+ * @since 6.2.0
+ *
+ * @param string $link The URL to test.
+ * @return bool Returns true for internal URLs and false for all other URLs.
+ */
+function wp_is_internal_link( $link ) {
+ $link = strtolower( $link );
+ if ( in_array( wp_parse_url( $link, PHP_URL_SCHEME ), wp_allowed_protocols(), true ) ) {
+ return in_array( wp_parse_url( $link, PHP_URL_HOST ), wp_internal_hosts(), true );
+ }
+ return false;
+}
</ins></span></pre></div>
<a id="trunktestsphpunittestsformattingmakeClickablephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/formatting/makeClickable.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/formatting/makeClickable.php 2023-02-07 18:50:01 UTC (rev 55288)
+++ trunk/tests/phpunit/tests/formatting/makeClickable.php 2023-02-07 18:52:24 UTC (rev 55289)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -108,12 +108,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'There was a spoon named www.wordpress.org) said Alice.',
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> $urls_expected = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>. Alice!',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>, said Alice.',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>; said Alice.',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>: said Alice.',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>) said Alice.',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "<a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>",
+ "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>. Alice!",
+ "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>, said Alice.",
+ "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>; said Alice.",
+ "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>: said Alice.",
+ "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>) said Alice.",
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $urls_before as $key => $url ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -135,12 +135,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'There was a spoon named www.wordpress.org)',
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> $urls_expected = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>.',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>,',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>;',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>:',
- 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>)',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "<a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>",
+ "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>.",
+ "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>,",
+ "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>;",
+ "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>:",
+ "There was a spoon named <a href='http://www.wordpress.org' rel=\"nofollow\">http://www.wordpress.org</a>)",
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $urls_before as $key => $url ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -217,7 +217,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'In his famous speech “You and Your research” (here: http://www.cs.virginia.edu/~robins/YouAndYourResearch.html) Richard Hamming wrote about people getting more done with their doors closed...',
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> $urls_expected = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'Example: WordPress, test (some text), I love example.com (<a href="http://example.org" rel="nofollow">http://example.org</a>), it is brilliant',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'Example: WordPress, test (some text), I love example.com (<a href="http://example.org">http://example.org</a>), it is brilliant',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'Example: WordPress, test (some text), I love example.com (<a href="http://example.com" rel="nofollow">http://example.com</a>), it is brilliant',
</span><span class="cx" style="display: block; padding: 0 10px"> 'Some text followed by a bracketed link with a trailing elipsis (<a href="http://example.com" rel="nofollow">http://example.com</a>)...',
</span><span class="cx" style="display: block; padding: 0 10px"> 'In his famous speech “You and Your research” (here: <a href="http://www.cs.virginia.edu/~robins/YouAndYourResearch.html" rel="nofollow">http://www.cs.virginia.edu/~robins/YouAndYourResearch.html</a>) Richard Hamming wrote about people getting more done with their doors closed...',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -421,6 +421,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 48022
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 56444
</ins><span class="cx" style="display: block; padding: 0 10px"> * @dataProvider data_add_rel_ugc_in_comments
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_add_rel_ugc_in_comments( $content, $expected ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -438,7 +439,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public function data_add_rel_ugc_in_comments() {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $home_url_http = set_url_scheme( home_url(), 'http' );
+ $home_url_https = set_url_scheme( home_url(), 'https' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> return array(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // @ticket 48022
</ins><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'http://wordpress.org',
</span><span class="cx" style="display: block; padding: 0 10px"> '<a href="http://wordpress.org" rel="nofollow ugc">http://wordpress.org</a>',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -445,8 +451,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'www.wordpress.org',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- '<p><a href="http://www.wordpress.org" rel="nofollow ugc">http://www.wordpress.org</a>',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ '<p><a href=\'http://www.wordpress.org\' rel="nofollow ugc">http://www.wordpress.org</a>',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // @ticket 56444
+ array(
+ 'www.example.org',
+ '<p><a href=\'http://www.example.org\' rel="nofollow ugc">http://www.example.org</a>',
+ ),
+ array(
+ $home_url_http,
+ '<a href="' . $home_url_http . '" rel="ugc">' . $home_url_http . '</a>',
+ ),
+ array(
+ $home_url_https,
+ '<a href="' . $home_url_https . '" rel="ugc">' . $home_url_https . '</a>',
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunktestsphpunittestsformattingwpRelNofollowphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/formatting/wpRelNofollow.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/formatting/wpRelNofollow.php 2023-02-07 18:50:01 UTC (rev 55288)
+++ trunk/tests/phpunit/tests/formatting/wpRelNofollow.php 2023-02-07 18:52:24 UTC (rev 55289)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -11,16 +11,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 9959
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_add_no_follow() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( PHP_VERSION_ID >= 80100 ) {
- /*
- * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
- * via hooked in filter functions until a more structural solution to the
- * "missing input validation" conundrum has been architected and implemented.
- */
- $this->expectDeprecation();
- $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> $content = '<p>This is some cool <a href="/">Code</a></p>';
</span><span class="cx" style="display: block; padding: 0 10px"> $expected = '<p>This is some cool <a href=\"/\" rel=\"nofollow\">Code</a></p>';
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $expected, wp_rel_nofollow( $content ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -30,16 +20,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 9959
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_convert_no_follow() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( PHP_VERSION_ID >= 80100 ) {
- /*
- * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
- * via hooked in filter functions until a more structural solution to the
- * "missing input validation" conundrum has been architected and implemented.
- */
- $this->expectDeprecation();
- $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> $content = '<p>This is some cool <a href="/" rel="weird">Code</a></p>';
</span><span class="cx" style="display: block; padding: 0 10px"> $expected = '<p>This is some cool <a href=\"/\" rel=\"weird nofollow\">Code</a></p>';
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $expected, wp_rel_nofollow( $content ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -50,16 +30,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @dataProvider data_wp_rel_nofollow
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_wp_rel_nofollow( $input, $output, $expect_deprecation = false ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( true === $expect_deprecation && PHP_VERSION_ID >= 80100 ) {
- /*
- * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
- * via hooked in filter functions until a more structural solution to the
- * "missing input validation" conundrum has been architected and implemented.
- */
- $this->expectDeprecation();
- $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( wp_slash( $output ), wp_rel_nofollow( $input ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -109,16 +79,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_append_no_follow_with_valueless_attribute() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( PHP_VERSION_ID >= 80100 ) {
- /*
- * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
- * via hooked in filter functions until a more structural solution to the
- * "missing input validation" conundrum has been architected and implemented.
- */
- $this->expectDeprecation();
- $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> $content = '<p>This is some cool <a href="demo.com" download rel="hola">Code</a></p>';
</span><span class="cx" style="display: block; padding: 0 10px"> $expected = '<p>This is some cool <a href=\"demo.com\" download rel=\"hola nofollow\">Code</a></p>';
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $expected, wp_rel_nofollow( $content ) );
</span></span></pre></div>
<a id="trunktestsphpunittestsformattingwpRelUgcphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/formatting/wpRelUgc.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/formatting/wpRelUgc.php 2023-02-07 18:50:01 UTC (rev 55288)
+++ trunk/tests/phpunit/tests/formatting/wpRelUgc.php 2023-02-07 18:52:24 UTC (rev 55289)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -11,16 +11,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 48022
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_add_ugc() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( PHP_VERSION_ID >= 80100 ) {
- /*
- * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
- * via hooked in filter functions until a more structural solution to the
- * "missing input validation" conundrum has been architected and implemented.
- */
- $this->expectDeprecation();
- $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> $content = '<p>This is some cool <a href="/">Code</a></p>';
</span><span class="cx" style="display: block; padding: 0 10px"> $expected = '<p>This is some cool <a href=\"/\" rel=\"nofollow ugc\">Code</a></p>';
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $expected, wp_rel_ugc( $content ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -30,16 +20,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 48022
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_convert_ugc() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( PHP_VERSION_ID >= 80100 ) {
- /*
- * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
- * via hooked in filter functions until a more structural solution to the
- * "missing input validation" conundrum has been architected and implemented.
- */
- $this->expectDeprecation();
- $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> $content = '<p>This is some cool <a href="/" rel="weird">Code</a></p>';
</span><span class="cx" style="display: block; padding: 0 10px"> $expected = '<p>This is some cool <a href=\"/\" rel=\"weird nofollow ugc\">Code</a></p>';
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $expected, wp_rel_ugc( $content ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -50,16 +30,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @dataProvider data_wp_rel_ugc
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_wp_rel_ugc( $input, $output, $expect_deprecation = false ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( true === $expect_deprecation && PHP_VERSION_ID >= 80100 ) {
- /*
- * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
- * via hooked in filter functions until a more structural solution to the
- * "missing input validation" conundrum has been architected and implemented.
- */
- $this->expectDeprecation();
- $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( wp_slash( $output ), wp_rel_ugc( $input ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -99,25 +69,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> '<a href="' . $home_url_http . '/some-url">Home URL (http)</a>',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- '<a href="' . $home_url_http . '/some-url">Home URL (http)</a>',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ '<a href="' . $home_url_http . '/some-url" rel="ugc">Home URL (http)</a>',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> '<a href="' . $home_url_https . '/some-url">Home URL (https)</a>',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- '<a href="' . $home_url_https . '/some-url">Home URL (https)</a>',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ '<a href="' . $home_url_https . '/some-url" rel="ugc">Home URL (https)</a>',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_append_ugc_with_valueless_attribute() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( PHP_VERSION_ID >= 80100 ) {
- /*
- * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
- * via hooked in filter functions until a more structural solution to the
- * "missing input validation" conundrum has been architected and implemented.
- */
- $this->expectDeprecation();
- $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
- }
</del><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $content = '<p>This is some cool <a href="demo.com" download rel="hola">Code</a></p>';
</span><span class="cx" style="display: block; padding: 0 10px"> $expected = '<p>This is some cool <a href=\"demo.com\" download rel=\"hola nofollow ugc\">Code</a></p>';
</span></span></pre>
</div>
</div>
</body>
</html>