Opened 8 years ago
Closed 8 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 |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.5 |
Component: | General | Keywords: | reporter-feedback |
Focuses: | Cc: |
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)
#1
@
8 years ago
- Owner set to swissspidy
- Status changed from new to assigned
- Version changed from 4.6 to 4.5
#4
@
8 years ago
- Keywords close removed
- Milestone Awaiting Review deleted
- Resolution set to worksforme
- Status changed from assigned to closed
Closing after no feedback for over 4 months and no clear indication of a bug here. Feel free to reopen if necessary, ideally with a unit test showing the bug.
Note: See
TracTickets for help on using
tickets.
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.