Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

mail_to :javascript should use decodeURIComponent instead unescape

#648

If the 'name' parameter for mail_to contains unicode characters, these will not show properly in the link. Solution involves using to_json before outputing each byte.

Example:

mail_to "xxx@example.com", "Écris-nous", :encode=>:javascript

The link's label will show as "Écris-nous".

Solution:

Modify mail_to's code:

-   "document.write('#{content_tag("a", name || email_address, html_options.merge({ "href" => "mailto:"+email_address+extras }))}');".each_byte do |c|
+   "document.write('#{content_tag("a", (name || email_address).to_json[1..-2], html_options.merge({ "href" => "mailto:"+email_address+extras }))}');".each_byte do |c|

Temporary solution for affected users: call to_json yourself, as in:

mail_to "xxx@example.com", "Écris-nous", :encode=>:javascript

Reported by Marc-André Lafortune · July 17th, 2008 @ 10:45 PM

State: committed
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Marc-André Lafortune
    Marc-André Lafortune

    Oups, managed to screw up my very first ticket... The example should read:

    mail_to "xxx@example.com", "Écris-nous", :encode=>:javascript
    

    and the temporary fix:

    mail_to "xxx@example.com", "Écris-nous".to_json[1..-2], :encode=>:javascript
    

    July 17th, 2008 @ 10:50 PM

  2. Emilio Tagua
    Emilio Tagua
    • Title changed from mail_to :javascript screws up unicode to mail_to :javascript should use decodeURIComponent instead unescape
    • Tag set to actionpack, helper, patch

    Instead of using unescape to decode the generated string, Rails should use decodeURIComponent since it is utf-8 friendly.

    I attach the patch and test, i have also tested in browsers that the escaped javascript is the expected.

    July 31st, 2008 @ 09:30 PM

  3. Emilio Tagua
  4. Michael Koziarski
    Michael Koziarski
    • State changed from new to committed

    August 8th, 2008 @ 02:31 PM