dmails: fix bug with parsing wiki links in email notifications.
Bug: sending a dmail containing a wiki link (ex: [[tagme]]) failed when the recipient had email notifications turned on. Cause: wiki links inside email notifications use absolute urls, which the dtext postprocessor didn't parse correctly.
This commit is contained in:
@@ -28,7 +28,8 @@ class DText
|
||||
fragment = Nokogiri::HTML.fragment(html)
|
||||
|
||||
fragment.css("a.dtext-wiki-link").each do |node|
|
||||
name = node["href"][%r!\A/wiki_pages/(.*)\z!i, 1]
|
||||
path = Addressable::URI.parse(node["href"]).path
|
||||
name = path[%r!\A/wiki_pages/(.*)\z!i, 1]
|
||||
name = CGI.unescape(name)
|
||||
name = WikiPage.normalize_title(name)
|
||||
wiki = wiki_pages.find { |wiki| wiki.title == name }
|
||||
|
||||
@@ -55,6 +55,11 @@ class DTextTest < ActiveSupport::TestCase
|
||||
assert_match(/tag-type-#{Tag.categories.artist}/, DText.format_text("[[bkub]]"))
|
||||
end
|
||||
|
||||
should "parse wiki links correctly with the base_url option" do
|
||||
create(:tag, name: "bkub", category: Tag.categories.artist, post_count: 42)
|
||||
assert_match(/tag-type-#{Tag.categories.artist}/, DText.format_text("[[bkub]]", base_url: "http://www.example.com"))
|
||||
end
|
||||
|
||||
should "mark links to nonexistent tags or wikis" do
|
||||
create(:tag, name: "no_wiki", post_count: 42)
|
||||
create(:tag, name: "empty_tag", post_count: 0)
|
||||
|
||||
@@ -153,9 +153,9 @@ class DmailTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "send an email if the user wants it" do
|
||||
user = FactoryBot.create(:user, :receive_email_notifications => true)
|
||||
user = create(:user, receive_email_notifications: true)
|
||||
assert_difference("ActionMailer::Base.deliveries.size", 1) do
|
||||
FactoryBot.create(:dmail, :to => user, :owner => user)
|
||||
create(:dmail, to: user, owner: user, body: "test [[tagme]]")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user