Make WordPress Core

Opened 8 years ago

Closed 5 years ago

Last modified 5 years ago

#40049 closed defect (bug) (worksforme)

Javascript For-Loop Inside Shortcode (PHP) Breaks On Output

Reported by: kelderic's profile Kelderic Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Shortcodes Keywords:
Focuses: Cc:

Description

If I have a shortcode that outputs inline Javascript, placing a greater than arrow < will cause the following code to break.

Example:

add_shortcode('output-javascript', function() {

    $output = "

        <script>

            function getData() {


                for ( var i = 0; i < 5; i++ ) {

                    // run logic

                }

            }

            getData();

            console.log('<b>Text</b><br/>Second Line of text');

        </script>

    ";

    return $output;

});

If you place this as a shortcut, it would be expected that the contents of $output are displayed on the page. However, the closing </b> tag is stripped out. What is written to the page is this:

        <script>

            function getData() {


                for ( var i = 0; i < 5; i++ ) {

                    // run logic

                }

            }

            getData();

            console.log('<b>Text<br/>Second Line of text');

        </script>

});

Change History (4)

#1 @Kelderic
8 years ago

As a follow up, what causes the breakage is the < inside the For-Loop. Javascript that doesn't contain < will work perfectly.

This ticket was mentioned in Slack in #core by noisysocks. View the logs.


5 years ago

#3 @peterwilsoncc
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

I'm sorry for the length of time it took for a reply.

This was discussed in a triage meeting today and several people attempted to reproduce this bug without success. I'm going to close this as worksforme, which is trac's unfriendly way of saying it couldn't be reproduced.

If you're still experiencing the problem, are you able to provide further reproduction steps?

#4 @SergeyBiryukov
5 years ago

  • Component changed from General to Shortcodes
Note: See TracTickets for help on using tickets.