Formatting: Don't make links inside <script>
and <style>
tags clickable.
Fixes #30162 Props ninos-ego, adamsilverstein git-svn-id: https://develop.svn.wordpress.org/trunk@35847 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
08f67db8a3
commit
c2f597280b
@ -2195,9 +2195,9 @@ function make_clickable( $text ) {
|
||||
$nested_code_pre = 0; // Keep track of how many levels link is nested inside <pre> or <code>
|
||||
foreach ( $textarr as $piece ) {
|
||||
|
||||
if ( preg_match( '|^<code[\s>]|i', $piece ) || preg_match( '|^<pre[\s>]|i', $piece ) )
|
||||
if ( preg_match( '|^<code[\s>]|i', $piece ) || preg_match( '|^<pre[\s>]|i', $piece ) || preg_match( '|^<script[\s>]|i', $piece ) || preg_match( '|^<style[\s>]|i', $piece ) )
|
||||
$nested_code_pre++;
|
||||
elseif ( ( '</code>' === strtolower( $piece ) || '</pre>' === strtolower( $piece ) ) && $nested_code_pre )
|
||||
elseif ( $nested_code_pre && ( '</code>' === strtolower( $piece ) || '</pre>' === strtolower( $piece ) || '</script>' === strtolower( $piece ) || '</style>' === strtolower( $piece ) ) )
|
||||
$nested_code_pre--;
|
||||
|
||||
if ( $nested_code_pre || empty( $piece ) || ( $piece[0] === '<' && ! preg_match( '|^<\s*[\w]{1,20}+://|', $piece ) ) ) {
|
||||
|
@ -372,4 +372,30 @@ class Tests_Formatting_MakeClickable extends WP_UnitTestCase {
|
||||
href='mailto:someone@example.com'>someone@example.com</a>";
|
||||
$this->assertEquals( $html, make_clickable( $html ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_script_and_style_tags
|
||||
* @ticket 30162
|
||||
*/
|
||||
public function test_dont_link_script_and_style_tags( $tag ) {
|
||||
$this->assertEquals( $tag, make_clickable( $tag ) );
|
||||
}
|
||||
|
||||
public function data_script_and_style_tags() {
|
||||
return array(
|
||||
array(
|
||||
'<script>http://wordpress.org</script>',
|
||||
),
|
||||
array(
|
||||
'<style>http://wordpress.org</style>',
|
||||
),
|
||||
array(
|
||||
'<script type="text/javascript">http://wordpress.org</script>',
|
||||
),
|
||||
array(
|
||||
'<style type="text/css">http://wordpress.org</style>',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user