Skip to content

A platform for community discussion. Free, open, simple.

Apply the same url normalisation to embed_urls inserted in the PostCreator (#30641)

Angus McLeod427ea5301b68
diff --git a/lib/post_creator.rb b/lib/post_creator.rb
index dfb7dec31ba..d486fffb801 100644
--- a/lib/post_creator.rb
+++ b/lib/post_creator.rb
@@ -405,7 +405,7 @@ class PostCreator
TopicEmbed.new(
topic_id: @post.topic_id,
post_id: @post.id,
- embed_url: @opts[:embed_url],
+ embed_url: TopicEmbed.normalize_url(@opts[:embed_url]),
content_sha1: @opts[:embed_content_sha1],
)
rollback_from_errors!(embed) unless embed.save
diff --git a/spec/lib/post_creator_spec.rb b/spec/lib/post_creator_spec.rb
index 48f2b2dfdb1..9a72a92f049 100644
--- a/spec/lib/post_creator_spec.rb
+++ b/spec/lib/post_creator_spec.rb
@@ -1512,6 +1512,20 @@ RSpec.describe PostCreator do
expect(post.topic).not_to be_visible
end
end
+
+ it "normalizes the embed url" do
+ embed_url = "http://eviltrout.com/stupid-url/"
+ creator =
+ PostCreator.new(
+ user,
+ embed_url: embed_url,
+ title: "Reviews of Science Ovens",
+ raw: "Did you know that you can use microwaves to cook your dinner? Science!",
+ )
+ creator.create
+ expect(creator.errors).to be_blank
+ expect(TopicEmbed.where(embed_url: "http://eviltrout.com/stupid-url").exists?).to eq(true)
+ end
end
describe "read credit for creator" do