This project is archived and is in readonly mode.
mail_to :javascript should use decodeURIComponent instead unescape
Reported by Marc-André Lafortune | July 17th, 2008 @ 10:45 PM | in 2.x
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
Comments and changes to this ticket
-
Marc-André Lafortune July 17th, 2008 @ 10:50 PM
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
-
Emilio Tagua July 31st, 2008 @ 09:30 PM
- 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.
-
Emilio Tagua July 31st, 2008 @ 11:45 PM
- no changes were found...
-
Michael Koziarski August 8th, 2008 @ 02:31 PM
- State changed from new to committed
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>