[wp-trac] [WordPress Trac] #37877: Conversion of quotation marks in wp_add_inline_script() results in invalid JavaScript

WordPress Trac noreply at wordpress.org
Tue Aug 30 07:12:36 UTC 2016


#37877: Conversion of quotation marks in wp_add_inline_script() results in invalid
JavaScript
--------------------------+-----------------------------
 Reporter:  dboulet       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  4.6
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 A string containing JavaScript which is passed to wp_add_inline_script()
 is sometimes rendered invalid when strings within it contain quotation
 marks. As an example:

 {{{#!php
 <?php
 wp_add_inline_script( 'jquery-ui-datepicker', '"Aujourd\'hui";' );
 }}}

 will output the following:

 {{{
 <script>
 "Aujourd"hui";
 </script>
 }}}

 Interestingly, reversing the quotation marks results in the same output:

 {{{#!php
 <?php
 wp_add_inline_script( 'jquery-ui-datepicker', "'Aujourd\"hui';" );
 }}}

 also gives:

 {{{
 <script>
 "Aujourd"hui";
 </script>
 }}}

 Either way, valid JavaScript is passed in, and invalid scripts are spit
 out. Anyone know what is going on?

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


More information about the wp-trac mailing list