From: Anton Khorev Date: Thu, 20 Jun 2024 19:13:28 +0000 (+0300) Subject: Url-encode wikimedia_commons tag values X-Git-Tag: live~386^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/9f3ac8f5cec8c66789f70300dfe0fc54fb3bd9d5?ds=sidebyside;hp=-c Url-encode wikimedia_commons tag values --- 9f3ac8f5cec8c66789f70300dfe0fc54fb3bd9d5 diff --git a/app/helpers/browse_tags_helper.rb b/app/helpers/browse_tags_helper.rb index 867fe1273..e65bed092 100644 --- a/app/helpers/browse_tags_helper.rb +++ b/app/helpers/browse_tags_helper.rb @@ -116,9 +116,11 @@ module BrowseTagsHelper end def wikimedia_commons_link(key, value) - if key == "wikimedia_commons" && value =~ /^(?:file|category):/i + if key == "wikimedia_commons" && value =~ /^(file|category):(.+)$/i + namespace = Regexp.last_match(1) + title = Regexp.last_match(2) return { - :url => "//commons.wikimedia.org/wiki/#{value}?uselang=#{I18n.locale}", + :url => "//commons.wikimedia.org/wiki/#{namespace}:#{u title}?uselang=#{I18n.locale}", :title => value } end diff --git a/test/helpers/browse_tags_helper_test.rb b/test/helpers/browse_tags_helper_test.rb index 9bd11f052..1880012b0 100644 --- a/test/helpers/browse_tags_helper_test.rb +++ b/test/helpers/browse_tags_helper_test.rb @@ -245,6 +245,10 @@ class BrowseTagsHelperTest < ActionView::TestCase assert_equal "//commons.wikimedia.org/wiki/Category:Test_Category?uselang=en", link[:url] assert_equal "Category:Test_Category", link[:title] + link = wikimedia_commons_link("wikimedia_commons", "Category:What If? (Bonn)") + assert_equal "//commons.wikimedia.org/wiki/Category:What%20If%3F%20%28Bonn%29?uselang=en", link[:url] + assert_equal "Category:What If? (Bonn)", link[:title] + I18n.with_locale "pt-BR" do link = wikimedia_commons_link("wikimedia_commons", "File:Test.jpg") assert_equal "//commons.wikimedia.org/wiki/File:Test.jpg?uselang=pt-BR", link[:url]