]> git.openstreetmap.org Git - rails.git/blobdiff - app/helpers/browse_helper.rb
Escape fragment identifiers in wikipedia URLs
[rails.git] / app / helpers / browse_helper.rb
index 7ccfca334513b2cf0921add9909392acbd8deb53..a2d0e440ddbd9700667544f60b9a46fb32e5c4cf 100644 (file)
@@ -1,3 +1,5 @@
+require "uri"
+
 module BrowseHelper
   def printable_name(object, version = false)
     if object.id.is_a?(Array)
@@ -133,17 +135,19 @@ module BrowseHelper
       return nil
     end
 
-    if value =~ /^([^#]*)(#.*)/
+    if value =~ /^([^#]*)#(.*)/
       # Contains a reference to a section of the wikipedia article
       # Must break it up to correctly build the url
       value = $1
-      section = $2
+      section = "#" + $2
+      encoded_section = "#" + URI.encode($2.gsub(" ", "_")).gsub("%3A", ":").gsub("%", ".")
     else
       section = ""
+      encoded_section = ""
     end
 
     {
-      :url => "http://#{lang}.wikipedia.org/wiki/#{value}?uselang=#{I18n.locale}#{section}",
+      :url => "http://#{lang}.wikipedia.org/wiki/#{value}?uselang=#{I18n.locale}#{encoded_section}",
       :title => value + section
     }
   end