diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 5d6813c27b..fc982cc410 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -1606,8 +1606,15 @@ function _make_email_clickable_cb($matches) { function make_clickable( $text ) { $r = ''; $textarr = preg_split( '/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // split out HTML tags + $nested_code_pre = 0; // Keep track of how many levels link is nested inside
or
foreach ( $textarr as $piece ) {
- if ( empty( $piece ) || ( $piece[0] == '<' && ! preg_match('|^<\s*[\w]{1,20}+://|', $piece) ) ) {
+
+ if ( preg_match( '|^]|', $piece ) || preg_match( '|^]|', $piece ) )
+ $nested_code_pre++;
+ elseif ( ( '
' === $piece || '' === $piece ) && $nested_code_pre )
+ $nested_code_pre--;
+
+ if ( $nested_code_pre || empty( $piece ) || ( $piece[0] === '<' && ! preg_match( '|^<\s*[\w]{1,20}+://|', $piece ) ) ) {
$r .= $piece;
continue;
}
diff --git a/tests/phpunit/tests/formatting/MakeClickable.php b/tests/phpunit/tests/formatting/MakeClickable.php
index 63ad5559a2..221635d72a 100644
--- a/tests/phpunit/tests/formatting/MakeClickable.php
+++ b/tests/phpunit/tests/formatting/MakeClickable.php
@@ -288,6 +288,46 @@ class Tests_Formatting_MakeClickable extends WP_UnitTestCase {
}
}
+ /**
+ * @ticket 23756
+ */
+ function test_no_links_inside_pre_or_code() {
+ $before = array(
+ 'http://wordpress.org', + '
http://wordpress.org',
+ 'http://wordpress.org', + '
http://wordpress.org',
+ 'http://wordpress.org', + 'URL before code http://wordpress.org
http://wordpress.org',
+ 'URL after pre http://wordpress.orghttp://wordpress.org', + 'URL after code
http://wordpress.orghttp://wordpress.org',
+ 'URL before and after pre http://wordpress.orghttp://wordpress.orghttp://wordpress.org', + 'URL before and after code http://wordpress.org
http://wordpress.orghttp://wordpress.org',
+ 'code inside pre http://wordpress.org http://wordpress.org http://wordpress.org',
+ );
+
+ $expected = array(
+ 'http://wordpress.org', + '
http://wordpress.org',
+ 'http://wordpress.org', + '
http://wordpress.org',
+ 'http://wordpress.org', + 'URL before code http://wordpress.org
http://wordpress.org',
+ 'URL after pre http://wordpress.orghttp://wordpress.org', + 'URL after code
http://wordpress.orghttp://wordpress.org',
+ 'URL before and after pre http://wordpress.orghttp://wordpress.orghttp://wordpress.org', + 'URL before and after code http://wordpress.org
http://wordpress.orghttp://wordpress.org',
+ 'code inside pre http://wordpress.org http://wordpress.org http://wordpress.org',
+ );
+
+ foreach ( $before as $key => $url )
+ $this->assertEquals( $expected[ $key ], make_clickable( $url ) );
+ }
+
/**
* @ticket 16892
*/