From 06820acc4b3c818ad0e5d282490ac8413d966151 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sat, 22 Jun 2024 21:48:42 +0300 Subject: [PATCH] Discard fragments from wikimedia_commons tag values --- app/helpers/browse_tags_helper.rb | 2 +- test/helpers/browse_tags_helper_test.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/helpers/browse_tags_helper.rb b/app/helpers/browse_tags_helper.rb index e65bed092..bb79d9eaf 100644 --- a/app/helpers/browse_tags_helper.rb +++ b/app/helpers/browse_tags_helper.rb @@ -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 { diff --git a/test/helpers/browse_tags_helper_test.rb b/test/helpers/browse_tags_helper_test.rb index 1880012b0..990aed5e4 100644 --- a/test/helpers/browse_tags_helper_test.rb +++ b/test/helpers/browse_tags_helper_test.rb @@ -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] -- 2.39.5