]> git.openstreetmap.org Git - rails.git/commitdiff
Discard fragments from wikimedia_commons tag values
authorAnton Khorev <tony29@yandex.ru>
Sat, 22 Jun 2024 18:48:42 +0000 (21:48 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sat, 22 Jun 2024 18:48:42 +0000 (21:48 +0300)
app/helpers/browse_tags_helper.rb
test/helpers/browse_tags_helper_test.rb

index e65bed092b7486089354c173ab1cc35c04d18ef7..bb79d9eaf156ecfb2154ffbfd5021578936ea233 100644 (file)
@@ -116,7 +116,7 @@ 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 {
index 1880012b073754992dac17fd099a410ee0a204de..990aed5e437e0b31ea6843c35670cedfec1eb792 100644 (file)
@@ -249,6 +249,10 @@ class BrowseTagsHelperTest < ActionView::TestCase
     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]
 
+    link = wikimedia_commons_link("wikimedia_commons", "File:Corsica-vizzavona-abri-southwell.jpg#mediaviewer/File:Corsica-vizzavona-abri-southwell.jpg")
+    assert_equal "//commons.wikimedia.org/wiki/File:Corsica-vizzavona-abri-southwell.jpg?uselang=en", link[:url]
+    assert_equal "File:Corsica-vizzavona-abri-southwell.jpg#mediaviewer/File:Corsica-vizzavona-abri-southwell.jpg", 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]