]> git.openstreetmap.org Git - rails.git/commitdiff
Decode entities in the title
authorTom Hughes <tom@compton.nu>
Wed, 18 Jun 2014 08:25:01 +0000 (09:25 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 18 Jun 2014 08:29:17 +0000 (09:29 +0100)
They will get reencoded (if necessary) when they are output. Fixes #764.

app/helpers/title_helper.rb
test/helpers/title_helper_test.rb

index 8cacdf2085a7dbf425406c4c33475ea12ec618e5..a1a2125a173f81a72f2b53dcdccecdb3b9322e3f 100644 (file)
@@ -1,7 +1,11 @@
+require 'htmlentities'
+
 module TitleHelper
 module TitleHelper
+  @@coder = HTMLEntities.new
+
   def set_title(title = false)
     if title
   def set_title(title = false)
     if title
-      @title = title.gsub("<bdi>", "\u202a").gsub("</bdi>", "\u202c")
+      @title = @@coder.decode(title.gsub("<bdi>", "\u202a").gsub("</bdi>", "\u202c"))
       response.headers["X-Page-Title"] = t('layouts.project_name.title') + ' | ' + @title
     else
       @title = title
       response.headers["X-Page-Title"] = t('layouts.project_name.title') + ' | ' + @title
     else
       @title = title
index cf7a1124398932f6d9c5e9be515e9fe76e6fa01d..11578cc111d2e65265d7d59e123cf464dc521612 100644 (file)
@@ -9,5 +9,9 @@ class TitleHelperTest < ActionView::TestCase
     set_title("Test Title")
     assert_equal "OpenStreetMap | Test Title", response.header["X-Page-Title"]
     assert_equal "Test Title", @title
     set_title("Test Title")
     assert_equal "OpenStreetMap | Test Title", response.header["X-Page-Title"]
     assert_equal "Test Title", @title
+
+    set_title("Test & Title")
+    assert_equal "OpenStreetMap | Test & Title", response.header["X-Page-Title"]
+    assert_equal "Test & Title", @title
   end
 end
   end
 end