A platform for community discussion. Free, open, simple.
FIX: Embedded topic was not found when URL contained query string
Gerhard Schlager5a56746610e2
diff --git a/app/models/topic_embed.rb b/app/models/topic_embed.rbindex 8e3071ea4c8..2f2b26e1952 100644--- a/app/models/topic_embed.rb+++ b/app/models/topic_embed.rb@@ -183,7 +183,7 @@ class TopicEmbed < ActiveRecord::Basedef self.topic_id_for_embed(embed_url)embed_url = normalize_url(embed_url).sub(/^https?\:\/\//, '')- TopicEmbed.where("embed_url ~* '^https?://#{embed_url}$'").pluck(:topic_id).first+ TopicEmbed.where("embed_url ~* '^https?://#{Regexp.escape(embed_url)}$'").pluck(:topic_id).firstenddef self.first_paragraph_from(html)diff --git a/spec/models/topic_embed_spec.rb b/spec/models/topic_embed_spec.rbindex 447e8ff667f..1f00c699ec0 100644--- a/spec/models/topic_embed_spec.rb+++ b/spec/models/topic_embed_spec.rb@@ -72,6 +72,11 @@ describe TopicEmbed doexpect(TopicEmbed.topic_id_for_embed('http://example.com/post/24')).to eq(nil)expect(TopicEmbed.topic_id_for_embed('http://example.com/post')).to eq(nil)end++ it "finds the topic id when the embed_url contains a query string" do+ topic_embed = Fabricate(:topic_embed, embed_url: "http://example.com/post/248?key=foo")+ expect(TopicEmbed.topic_id_for_embed('http://example.com/post/248?key=foo')).to eq(topic_embed.topic_id)+ endenddescribe '.find_remote' do