]> git.openstreetmap.org Git - rails.git/blobdiff - app/helpers/application_helper.rb
Escape non-ascii characters in exported HTML. Closes #2075.
[rails.git] / app / helpers / application_helper.rb
index bee4f9ce2f4dc5a6ec30ab8fb90b816675da3860..ab0ba82a830f0440dee2273edb2bf2bf9f34febc 100644 (file)
@@ -3,6 +3,14 @@ module ApplicationHelper
     return sanitize(auto_link(simple_format(text), :urls))
   end
 
+  def html_escape_unicode(text)
+    chars = ActiveSupport::Multibyte::Chars.u_unpack(text).map do |c|
+      c < 127 ? c.chr : "&##{c.to_s};"
+    end
+
+    return chars.join("")
+  end
+
   def rss_link_to(*args)
     return link_to(image_tag("RSS.gif", :size => "16x16", :border => 0), Hash[*args], { :class => "rsssmall" });
   end