Opened 10 years ago
Closed 9 years ago
#37877 closed defect (bug) (worksforme)
Conversion of quotation marks in wp_add_inline_script() results in invalid JavaScript
| Reported by: | dboulet | Owned by: | swissspidy |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | General | Version: | 4.5 |
| Severity: | normal | Keywords: | reporter-feedback |
| Cc: | Focuses: |
Description
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 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 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?
Attachments (1)
Change History (5)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
I cannot seem to reproduce this. See attached test in 37877.diff. The output is
<script type='text/javascript'>"Aujourd'hui";</script>as expected.Can you give us some more info? Does the test work on your system?
The quotation marks you use for the string are irrelevant. PHP will only see what's inside, i.e.
'Aujourd\"hui';in your second example.