Formatting: Restore consistent quotes in _make_web_ftp_clickable_cb().

After the introduction of `_make_clickable_rel_attr()` in an earlier commit, the function ended up returning link markup with a mix of single and double quotes.

This commit ensures that `_make_web_ftp_clickable_cb()` always returns double quotes, restoring consistency with other similar callback functions used by `make_clickable()`:
* `_make_url_clickable_cb()`
* `_make_email_clickable_cb()`

Follow-up to [55289].

See #53290, #56444.

git-svn-id: https://develop.svn.wordpress.org/trunk@55495 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2023-03-09 00:18:29 +00:00
parent a67b087a20
commit 16901ff4ca
3 changed files with 23 additions and 25 deletions

View File

@@ -239,16 +239,15 @@ function get_comment_author_link( $comment_id = 0 ) {
*
* @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
* @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.
// Empty space before 'rel' is necessary for later sprintf().
$rel = ! empty( $rel ) ? sprintf( ' rel="%s"', $rel ) : '';
$return = sprintf(

View File

@@ -2918,8 +2918,8 @@ function _make_url_clickable_cb( $matches ) {
}
$rel_attr = _make_clickable_rel_attr( $url );
return $matches[1] . "<a href=\"$url\"$rel_attr>$url</a>" . $suffix;
return $matches[1] . "<a href=\"{$url}\"{$rel_attr}>{$url}</a>" . $suffix;
}
/**
@@ -2951,7 +2951,8 @@ function _make_web_ftp_clickable_cb( $matches ) {
}
$rel_attr = _make_clickable_rel_attr( $dest );
return $matches[1] . "<a href='{$dest}'{$rel_attr}>{$dest}</a>{$ret}";
return $matches[1] . "<a href=\"{$dest}\"{$rel_attr}>{$dest}</a>{$ret}";
}
/**
@@ -2967,7 +2968,8 @@ function _make_web_ftp_clickable_cb( $matches ) {
*/
function _make_email_clickable_cb( $matches ) {
$email = $matches[2] . '@' . $matches[3];
return $matches[1] . "<a href=\"mailto:$email\">$email</a>";
return $matches[1] . "<a href=\"mailto:{$email}\">{$email}</a>";
}
/**
@@ -2979,7 +2981,6 @@ function _make_email_clickable_cb( $matches ) {
* @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' ) );
@@ -3009,7 +3010,6 @@ function _make_clickable_rel_attr( $url ) {
$rel_attr = $rel ? ' rel="' . esc_attr( $rel ) . '"' : '';
return $rel_attr;
}
/**

View File

@@ -108,12 +108,12 @@ class Tests_Formatting_MakeClickable extends WP_UnitTestCase {
'There was a spoon named www.wordpress.org) said Alice.',
);
$urls_expected = array(
"<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.",
'<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.',
);
foreach ( $urls_before as $key => $url ) {
@@ -135,12 +135,12 @@ class Tests_Formatting_MakeClickable extends WP_UnitTestCase {
'There was a spoon named www.wordpress.org)',
);
$urls_expected = array(
"<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>)",
'<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>)',
);
foreach ( $urls_before as $key => $url ) {
@@ -439,7 +439,6 @@ class Tests_Formatting_MakeClickable extends WP_UnitTestCase {
}
public function data_add_rel_ugc_in_comments() {
$home_url_http = set_url_scheme( home_url(), 'http' );
$home_url_https = set_url_scheme( home_url(), 'https' );
@@ -451,12 +450,12 @@ class Tests_Formatting_MakeClickable extends WP_UnitTestCase {
),
array(
'www.wordpress.org',
'<p><a href=\'http://www.wordpress.org\' rel="nofollow ugc">http://www.wordpress.org</a>',
'<p><a href="http://www.wordpress.org" rel="nofollow ugc">http://www.wordpress.org</a>',
),
// @ticket 56444
array(
'www.example.org',
'<p><a href=\'http://www.example.org\' rel="nofollow ugc">http://www.example.org</a>',
'<p><a href="http://www.example.org" rel="nofollow ugc">http://www.example.org</a>',
),
array(
$home_url_http,