WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 5 months ago

#33840 new defect (bug)

wpautop damages inline script

Reported by: opajaap Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.3
Component: Formatting Keywords: wpautop
Focuses: Cc:
PR Number:

Description

This code:

$str = '
<script type="text/javascript">
alert( \'<div style="float:right; margin-right:6px;" >Edit</div><div style="float:right; margin-right:6px;" >Delete</div>\' );
</script>';
echo $str;
echo '<br/>';
echo wpautop($str);

results in this output as seen in the page source:

<script type="text/javascript">
alert( '<div style="float:right; margin-right:6px;" >Edit</div><div style="float:right; margin-right:6px;" >Delete</div>' );
</script><br/><p><script type="text/javascript">
alert( '
<div style="float:right; margin-right:6px;" >Edit</div>
<div style="float:right; margin-right:6px;" >Delete</div>
<p>' );
</script></p>

The wpautop filter adds <p> twice and </p> once; adds linebreaks and hence a js error: SyntaxError: unterminated string literal

To my opinion, wpautop should NEVER change a byte between <script> and </script>; neither should the script tag be wrapped in a p tag.
Wrapping the code in a [CDATA[ ]] block makes no difference.

This behaviour is noticed for years and is still present at version 4.4-alpha-34061

Change History (2)

#1 @iseulde
4 years ago

  • Component changed from General to Formatting

#2 @miqrogroove
4 years ago

  • Keywords wpautop added

Need to check this ticket for versioning and duplicates.

Note: See TracTickets for help on using tickets.