Escape fragment identifiers in wikipedia URLs

Fixes #967
This commit is contained in:
Tom Hughes 2015-05-14 20:34:25 +01:00
parent b2784c4d2d
commit b40353b9b0
2 changed files with 15 additions and 3 deletions

View 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