[wp-trac] [WordPress Trac] #40049: Javascript For-Loop Inside Shortcode (PHP) Breaks On Output

WordPress Trac noreply at wordpress.org
Mon Mar 6 18:46:15 UTC 2017


#40049: Javascript For-Loop Inside Shortcode (PHP) Breaks On Output
--------------------------+-----------------------------
 Reporter:  Kelderic      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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>

 });

 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40049>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list