[wp-trac] [WordPress Trac] #18240: wp_localize_script() shouldn't convert character entities

WordPress Trac wp-trac at lists.automattic.com
Mon Jul 25 09:31:32 UTC 2011


#18240: wp_localize_script() shouldn't convert character entities
--------------------------+-----------------------------
 Reporter:  johnbillion   |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  I18N          |    Version:  3.2.1
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 If you pass a string to `wp_localize_script()` which contains special HTML
 characters such as "&" they'll get converted to their entities, resulting
 in JavaScript strings that contain entities when they shouldn't. Looks
 like the entity conversion in `esc_js()` is the culprit.

 Example:

 {{{
 wp_localize_script(
         'myscript',
         'something',
         array(
                 'message'  => __( 'This & that', 'something' )
         )
 );
 }}}

 If you then do this:

 {{{
 alert( something.message );
 }}}

 the alert modal will show:

 {{{
 This & that
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18240>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list