WordPress.org

Make WordPress Core

Changeset 45577


Ignore:
Timestamp:
07/01/2019 03:18:28 AM (11 months ago)
Author:
pento
Message:

Formatting: Don't add <p> tags inside <svg> tags.

Inline <svg>s should generally work, as browsers should just ignore <p> or <br/> tags that shouldn't be inside the <svg>. To keep things neat, however, it's better not add them in the first place.

Props jared_smith, nacin, pento.
Fixes #9437.

Location:
trunk
Files:
2 edited

Legend:

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

    r45574 r45577  
    581581    if ( $br ) {
    582582        // Replace newlines that shouldn't be touched with a placeholder.
    583         $pee = preg_replace_callback( '/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee );
     583        $pee = preg_replace_callback( '/<(script|style|svg).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee );
    584584
    585585        // Normalize <br>
  • trunk/tests/phpunit/tests/formatting/Autop.php

    r45574 r45577  
    567567        $this->assertEquals( $expected, trim( wpautop( $content ) ) );
    568568    }
     569
     570    /**
     571     * wpautop() should ignore inline SVG graphics
     572     *
     573     * @ticket 9437
     574     */
     575    function test_that_wpautop_ignores_inline_svgs() {
     576        $content =
     577            '<svg xmlns="http://www.w3.org/2000/svg">
     578                <circle cx="50" cy="50" r="30" fill="blue">
     579                    <animateTransform attributeName="transform" type="scale" to="1.5" dur="2s" fill="freeze"/>
     580                </circle>
     581            </svg>';
     582
     583        $expected = '<p>' . $content . '</p>';
     584
     585        $this->assertEquals( $expected, trim( wpautop( $content ) ) );
     586    }
     587
     588    /**
     589     * wpautop() should ignore inline scripts
     590     *
     591     * @ticket 9437
     592     */
     593    function test_that_wpautop_ignores_inline_scripts() {
     594        $content =
     595            '<script type="text/javascript">
     596                var dummy = 1;
     597            </script>';
     598
     599        $expected = '<p>' . $content . '</p>';
     600
     601        $this->assertEquals( $expected, trim( wpautop( $content ) ) );
     602    }
    569603}
Note: See TracChangeset for help on using the changeset viewer.