I'm using h to HTML encode some text in Rails 2, but I'm having problems with apostrophes. To be more exact, I'm finding that my apostrophes end up as ' which is obviously not want I want to display.
Anyone have any ideas why this is happening? My research has implied HTML encoding shouldn't affect apostrophes.
This is an interesting question. I'm seeing an inconsistency in how
hAKAhtml_escapehandles apostrophe AKA"'".According to the RDoc for ERB::Util 2.6.6:
In IRB I see:
EDIT:
Heh, it's a bug, or at least an inconsistency, in the
hmethod. Here's the source:Notice the string being passed to
gsubdoesn't contain"'"? That means the lookup for ESCAPE_TABLE doesn't get called for single-quote/apostrophe.And, we all know the crux of the biscuit is the apostrophe. :-)
I expect that if I look at the definition for
horhtml_escapein your version of Rails, we'll find the apostrophe is included in that string.The fix is either to upgrade your ERB/Erubis, or override the
h/html_escapedefinition to be correct. You can use the definition above as a starting point.