FIX: Embedded topic was not found when URL contained query string

This commit is contained in:
Gerhard Schlager 2018-02-14 00:28:16 +01:00
parent 22f0b0096d
commit 5a56746610
2 changed files with 6 additions and 1 deletions

View File

@ -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)

View File

@ -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