mirror of
https://github.com/discourse/discourse.git
synced 2025-03-26 22:28:52 +08:00
FIX: extract links in post processor
when oneboxes are not cached or are refreshed they can introduce new links, these links must be extracted otherwise you can not follow them
This commit is contained in:
parent
cb6d1632ba
commit
22b2f5285c
@ -29,9 +29,16 @@ class CookedPostProcessor
|
|||||||
optimize_urls
|
optimize_urls
|
||||||
pull_hotlinked_images(bypass_bump)
|
pull_hotlinked_images(bypass_bump)
|
||||||
grant_badges
|
grant_badges
|
||||||
|
extract_links
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# onebox may have added some links, so extract them now
|
||||||
|
def extract_links
|
||||||
|
TopicLink.extract_from(@post)
|
||||||
|
QuotedPost.extract_from(@post)
|
||||||
|
end
|
||||||
|
|
||||||
def has_emoji?
|
def has_emoji?
|
||||||
(@doc.css("img.emoji") - @doc.css(".quote img")).size > 0
|
(@doc.css("img.emoji") - @doc.css(".quote img")).size > 0
|
||||||
end
|
end
|
||||||
|
@ -478,6 +478,15 @@ describe CookedPostProcessor do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "extracts links" do
|
||||||
|
let(:post) { Fabricate(:post, raw: "sam has a blog at https://samsaffron.com") }
|
||||||
|
it "always re-extracts links on post process" do
|
||||||
|
TopicLink.destroy_all
|
||||||
|
CookedPostProcessor.new(post).post_process
|
||||||
|
expect(TopicLink.count).to eq(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "grant badges" do
|
context "grant badges" do
|
||||||
context "emoji inside a quote" do
|
context "emoji inside a quote" do
|
||||||
let(:post) { Fabricate(:post, raw: "time to eat some sweet [quote]:candy:[/quote] mmmm") }
|
let(:post) { Fabricate(:post, raw: "time to eat some sweet [quote]:candy:[/quote] mmmm") }
|
||||||
|
@ -150,8 +150,9 @@ describe PostCreator do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'extracts links from the post' do
|
it 'extracts links from the post' do
|
||||||
TopicLink.expects(:extract_from).with(instance_of(Post))
|
create_post(raw: "this is a link to the best site at https://google.com")
|
||||||
creator.create
|
creator.create
|
||||||
|
expect(TopicLink.count).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'queues up post processing job when saved' do
|
it 'queues up post processing job when saved' do
|
||||||
|
@ -387,8 +387,12 @@ describe PostsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "extracts links from the new body" do
|
it "extracts links from the new body" do
|
||||||
TopicLink.expects(:extract_from).with(post)
|
param = update_params
|
||||||
xhr :put, :update, update_params
|
param[:post][:raw] = 'I just visited this https://google.com so many cool links'
|
||||||
|
|
||||||
|
xhr :put, :update, param
|
||||||
|
expect(response).to be_success
|
||||||
|
expect(TopicLink.count).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't allow updating of deleted posts" do
|
it "doesn't allow updating of deleted posts" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user