This project is archived and is in readonly mode.

ActionView::Helpers::TextHelper#truncate should understand HTML encoding.
Reported by Gaius Centus Novus | December 18th, 2008 @ 05:13 PM | in 3.x
I'd like to use the HTML ellipsis (…) as my
:omission in #truncate. The problem is
that #truncate views that as a string of length 7, not
of length 1. That is,
truncate('A really long string', :length => 10, :omission => '…')
# => "A r…"
But since … is really a single character
in HTML, it should output "A real…".
Comments and changes to this ticket
- 
            
         Peter Wagenet December 18th, 2008 @ 07:52 PM- Tag changed from html, truncate, view to html, patch, tested, truncate, view
 The problem here is a bit more complicated that it seems. First, what if the user doesn't plan to format as HTML? I know that's an odd case, but should it be supported? If so, how do we know if "…" should be counted as one character or seven? If we do assume that it will always be output as HTML then counting it as one character is simple, as you can see in my attached patch. However, my patch does nothing about the case where we have special characters in the string to be truncated. Even worse, we could end up truncating in the middle of a special character which would be far from desired. There's probably the need for some additional work to be done here. 
- 
            
         Peter Wagenet December 18th, 2008 @ 07:53 PMThe ellipses in my comment should actually be the HTML string written out. 
- 
         Pratik December 22nd, 2008 @ 12:45 AM- Assigned user set to Pratik
- State changed from new to incomplete
 We could have used CGI::unescapeHTML here, except it doesn't seem to be working with …. So if there is a rack equivalent of that, it could work here. Thanks. 
- 
            
         Gaius Centus Novus December 22nd, 2008 @ 12:59 AMCGI::unescapeHTMLis completely borked. See my question on StackOverflow: http://stackoverflow.com/questio...
- 
         
- 
         
- 
            
         
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>
 Gaius Centus Novus
      Gaius Centus Novus
 Jeremy Kemper
      Jeremy Kemper
 Pratik
      Pratik
 Ryan Bigg
      Ryan Bigg