Changeset 26052
- Timestamp:
- 11/08/2013 10:37:41 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/formatting.php
r26050 r26052 1607 1607 $r = ''; 1608 1608 $textarr = preg_split( '/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // split out HTML tags 1609 $nested_code_pre = 0; // Keep track of how many levels link is nested inside <pre> or <code> 1609 1610 foreach ( $textarr as $piece ) { 1610 if ( empty( $piece ) || ( $piece[0] == '<' && ! preg_match('|^<\s*[\w]{1,20}+://|', $piece) ) ) { 1611 1612 if ( preg_match( '|^<code[\s>]|', $piece ) || preg_match( '|^<pre[\s>]|', $piece ) ) 1613 $nested_code_pre++; 1614 elseif ( ( '</code>' === $piece || '</pre>' === $piece ) && $nested_code_pre ) 1615 $nested_code_pre--; 1616 1617 if ( $nested_code_pre || empty( $piece ) || ( $piece[0] === '<' && ! preg_match( '|^<\s*[\w]{1,20}+://|', $piece ) ) ) { 1611 1618 $r .= $piece; 1612 1619 continue; -
trunk/tests/phpunit/tests/formatting/MakeClickable.php
r25264 r26052 290 290 291 291 /** 292 * @ticket 23756 293 */ 294 function test_no_links_inside_pre_or_code() { 295 $before = array( 296 '<pre>http://wordpress.org</pre>', 297 '<code>http://wordpress.org</code>', 298 '<pre class="foobar" id="foo">http://wordpress.org</pre>', 299 '<code class="foobar" id="foo">http://wordpress.org</code>', 300 '<precustomtag>http://wordpress.org</precustomtag>', 301 '<codecustomtag>http://wordpress.org</codecustomtag>', 302 'URL before pre http://wordpress.org<pre>http://wordpress.org</pre>', 303 'URL before code http://wordpress.org<code>http://wordpress.org</code>', 304 'URL after pre <pre>http://wordpress.org</pre>http://wordpress.org', 305 'URL after code <code>http://wordpress.org</code>http://wordpress.org', 306 'URL before and after pre http://wordpress.org<pre>http://wordpress.org</pre>http://wordpress.org', 307 'URL before and after code http://wordpress.org<code>http://wordpress.org</code>http://wordpress.org', 308 'code inside pre <pre>http://wordpress.org <code>http://wordpress.org</code> http://wordpress.org</pre>', 309 ); 310 311 $expected = array( 312 '<pre>http://wordpress.org</pre>', 313 '<code>http://wordpress.org</code>', 314 '<pre class="foobar" id="foo">http://wordpress.org</pre>', 315 '<code class="foobar" id="foo">http://wordpress.org</code>', 316 '<precustomtag><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a></precustomtag>', 317 '<codecustomtag><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a></codecustomtag>', 318 'URL before pre <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><pre>http://wordpress.org</pre>', 319 'URL before code <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><code>http://wordpress.org</code>', 320 'URL after pre <pre>http://wordpress.org</pre><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>', 321 'URL after code <code>http://wordpress.org</code><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>', 322 'URL before and after pre <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><pre>http://wordpress.org</pre><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>', 323 'URL before and after code <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><code>http://wordpress.org</code><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>', 324 'code inside pre <pre>http://wordpress.org <code>http://wordpress.org</code> http://wordpress.org</pre>', 325 ); 326 327 foreach ( $before as $key => $url ) 328 $this->assertEquals( $expected[ $key ], make_clickable( $url ) ); 329 } 330 331 /** 292 332 * @ticket 16892 293 333 */
Note: See TracChangeset
for help on using the changeset viewer.