WordPress.org

Make WordPress Core

Changeset 35847


Ignore:
Timestamp:
12/09/2015 11:54:24 PM (5 years ago)
Author:
johnbillion
Message:

Formatting: Don't make links inside <script> and <style> tags clickable.

Fixes #30162
Props ninos-ego, adamsilverstein

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r35813 r35847  
    21962196    foreach ( $textarr as $piece ) {
    21972197
    2198         if ( preg_match( '|^<code[\s>]|i', $piece ) || preg_match( '|^<pre[\s>]|i', $piece ) )
     2198        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 ) )
    21992199            $nested_code_pre++;
    2200         elseif ( ( '</code>' === strtolower( $piece ) || '</pre>' === strtolower( $piece ) ) && $nested_code_pre )
     2200        elseif ( $nested_code_pre && ( '</code>' === strtolower( $piece ) || '</pre>' === strtolower( $piece ) || '</script>' === strtolower( $piece ) || '</style>' === strtolower( $piece ) ) )
    22012201            $nested_code_pre--;
    22022202
  • trunk/tests/phpunit/tests/formatting/MakeClickable.php

    r30514 r35847  
    373373        $this->assertEquals( $html, make_clickable( $html ) );
    374374    }
     375
     376    /**
     377     * @dataProvider data_script_and_style_tags
     378     * @ticket 30162
     379     */
     380    public function test_dont_link_script_and_style_tags( $tag ) {
     381        $this->assertEquals( $tag, make_clickable( $tag ) );
     382    }
     383
     384    public function data_script_and_style_tags() {
     385        return array(
     386            array(
     387                '<script>http://wordpress.org</script>',
     388            ),
     389            array(
     390                '<style>http://wordpress.org</style>',
     391            ),
     392            array(
     393                '<script type="text/javascript">http://wordpress.org</script>',
     394            ),
     395            array(
     396                '<style type="text/css">http://wordpress.org</style>',
     397            ),
     398        );
     399    }
     400
    375401}
Note: See TracChangeset for help on using the changeset viewer.