Skip to content

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.rb
index 8e3071ea4c8..2f2b26e1952 100644
--- a/app/models/topic_embed.rb
+++ b/app/models/topic_embed.rb
@@ -183,7 +183,7 @@ class TopicEmbed < ActiveRecord::Base
def 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).first
end
def self.first_paragraph_from(html)
diff --git a/spec/models/topic_embed_spec.rb b/spec/models/topic_embed_spec.rb
index 447e8ff667f..1f00c699ec0 100644
--- a/spec/models/topic_embed_spec.rb
+++ b/spec/models/topic_embed_spec.rb
@@ -72,6 +72,11 @@ describe TopicEmbed do
expect(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)
+ end
end
describe '.find_remote' do