diff --git a/app/logical/d_text.rb b/app/logical/d_text.rb index 0aed9a0b5..ecacb4c64 100644 --- a/app/logical/d_text.rb +++ b/app/logical/d_text.rb @@ -37,8 +37,8 @@ class DText tag = tags.find { |tag| tag.name == name } artist = artists.find { |artist| artist.name == name } - if (tag.present? && tag.category == Tag.categories.artist) || artist.present? - node["href"] = "/artists/show_or_new?name=#{name}" + if tag.present? && tag.category == Tag.categories.artist + node["href"] = "/artists/show_or_new?name=#{CGI.escape(name)}" if artist.blank? node["class"] += " dtext-artist-does-not-exist" diff --git a/test/unit/d_text_test.rb b/test/unit/d_text_test.rb index 0c8cae591..7d627ef34 100644 --- a/test/unit/d_text_test.rb +++ b/test/unit/d_text_test.rb @@ -80,6 +80,23 @@ class DTextTest < ActiveSupport::TestCase assert_match(/implication ##{@ti.id}/, DText.format_text("[ti:#{@ti.id}]")) assert_match(/alias ##{@ta.id}/, DText.format_text("[ta:#{@ta.id}]")) end + + should "link artist tags to the artist page instead of the wiki page" do + tag = create(:tag, name: "m&m", category: Tag.categories.artist) + artist = create(:artist, name: "m&m") + + assert_equal( + '

m&m

', + DText.format_text("[[m&m]]") + ) + end + + should "not link general tags to artist pages" do + tag = create(:tag, name: "cat") + artist = create(:artist, name: "cat", is_active: false) + + assert_match(%r!/wiki_pages/cat!, DText.format_text("[[cat]]")) + end end context "#parse_wiki_titles" do