diff --git a/app/jobs/regular/process_post.rb b/app/jobs/regular/process_post.rb index cac70c050f0..0f44be43027 100644 --- a/app/jobs/regular/process_post.rb +++ b/app/jobs/regular/process_post.rb @@ -14,7 +14,9 @@ module Jobs recooked = nil if args[:cook].present? - recooked = post.cook(post.raw, topic_id: post.topic_id) + cooking_options = args[:cooking_options] || {} + cooking_options[:topic_id] = post.topic_id + recooked = post.cook(post.raw, cooking_options.symbolize_keys) post.update_column(:cooked, recooked) end diff --git a/app/models/post.rb b/app/models/post.rb index 16a2ce178aa..7799da3afce 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -507,6 +507,7 @@ class Post < ActiveRecord::Base } args[:image_sizes] = image_sizes if image_sizes.present? args[:invalidate_oneboxes] = true if invalidate_oneboxes.present? + args[:cooking_options] = self.cooking_options Jobs.enqueue(:process_post, args) DiscourseEvent.trigger(:after_trigger_post_process, self) end diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index 9c606a23dd4..01b20c6f638 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -11,7 +11,11 @@ class CookedPostProcessor @opts = opts @post = post @previous_cooked = (@post.cooked || "").dup - @doc = Nokogiri::HTML::fragment(post.cooked) + # NOTE: we re-cook the post here in order to prevent timing issues with edits + # cf. https://meta.discourse.org/t/edit-of-rebaked-post-doesnt-show-in-html-only-in-raw/33815/6 + cooking_options = post.cooking_options || opts[:cooking_options] || {} + cooking_options[:topic_id] = post.topic_id + @doc = Nokogiri::HTML::fragment(post.cook(post.raw, cooking_options.symbolize_keys)) @size_cache = {} end diff --git a/lib/post_creator.rb b/lib/post_creator.rb index 21b07963f57..22ace0dad38 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -176,7 +176,7 @@ class PostCreator cooking_options = post.cooking_options || {} cooking_options[:topic_id] = post.topic_id - post.cooked ||= post.cook(post.raw, cooking_options) + post.cooked ||= post.cook(post.raw, cooking_options.symbolize_keys) post.sort_order = post.post_number post.last_version_at ||= Time.now end diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index 683fdf855a7..e775d535424 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -118,9 +118,9 @@ describe CookedPostProcessor do it "generates overlay information" do cpp.post_process_images - expect(cpp.html).to match_html '
' expect(cpp).to be_dirty end @@ -145,9 +145,9 @@ describe CookedPostProcessor do it "generates overlay information" do cpp.post_process_images - expect(cpp.html).to match_html '' expect(cpp).to be_dirty end @@ -341,9 +341,7 @@ describe CookedPostProcessor do it "uses schemaless url for uploads" do cpp.optimize_urls - expect(cpp.html).to match_html 'Link - Google - ' + expect(cpp.html).to match_html '' end context "when CDN is enabled" do @@ -351,17 +349,13 @@ describe CookedPostProcessor do it "does use schemaless CDN url for http uploads" do Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com") cpp.optimize_urls - expect(cpp.html).to match_html 'Link - Google - ' + expect(cpp.html).to match_html '' end it "does not use schemaless CDN url for https uploads" do Rails.configuration.action_controller.stubs(:asset_host).returns("https://my.cdn.com") cpp.optimize_urls - expect(cpp.html).to match_html 'Link - Google - ' + expect(cpp.html).to match_html '' end end diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb index a94951d1840..4b460b3ada4 100644 --- a/spec/components/email/receiver_spec.rb +++ b/spec/components/email/receiver_spec.rb @@ -460,12 +460,8 @@ This is a link http://example.com" def fill_email(mail, from, to, body = nil, subject = nil) result = mail.gsub("FROM", from).gsub("TO", to) - if body - result.gsub!(/Hey.*/m, body) - end - if subject - result.sub!(/We .*/, subject) - end + result.gsub!(/Hey.*/m, body) if body + result.sub!(/We .*/, subject) if subject result end diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb index 5b492434229..cf5a4d4bfc6 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -445,7 +445,7 @@ describe PostCreator do raw: raw, cooking_options: { traditional_markdown_linebreaks: true }) - Post.any_instance.expects(:cook).with(raw, has_key(:traditional_markdown_linebreaks)).returns(raw) + Post.any_instance.expects(:cook).with(raw, has_key(:traditional_markdown_linebreaks)).twice.returns(raw) creator.create end end diff --git a/spec/fabricators/post_fabricator.rb b/spec/fabricators/post_fabricator.rb index 317238a611e..45ac7be16b5 100644 --- a/spec/fabricators/post_fabricator.rb +++ b/spec/fabricators/post_fabricator.rb @@ -12,6 +12,7 @@ Fabricator(:post_with_long_raw_content, from: :post) do end Fabricator(:post_with_youtube, from: :post) do + raw 'http://www.youtube.com/watch?v=9bZkp7q19f0' cooked 'http://www.youtube.com/watch?v=9bZkp7q19f0
' end @@ -53,44 +54,44 @@ Fabricator(:post_with_plenty_of_images, from: :post) do end Fabricator(:post_with_uploaded_image, from: :post) do - cooked '' + raw '' end Fabricator(:post_with_an_attachment, from: :post) do - cooked 'archive.zip' + raw 'archive.zip' end Fabricator(:post_with_unsized_images, from: :post) do - cooked ' + raw ' ' end Fabricator(:post_with_image_urls, from: :post) do - cooked ' + raw ' ' end Fabricator(:post_with_large_image, from: :post) do - cooked '' + raw '' end Fabricator(:post_with_large_image_and_title, from: :post) do - cooked '' + raw '' end Fabricator(:post_with_uploads, from: :post) do - cooked ' + raw ' Link ' end Fabricator(:post_with_uploads_and_links, from: :post) do - cooked ' + raw ' Link Google diff --git a/spec/fixtures/emails/paragraphs.cooked b/spec/fixtures/emails/paragraphs.cooked index da83260e09c..2d44722107d 100644 --- a/spec/fixtures/emails/paragraphs.cooked +++ b/spec/fixtures/emails/paragraphs.cooked @@ -4,4 +4,4 @@ is imported into new silos?The thing about candy is it stays delicious for a long time -- we can just keep it there without worrying about it too much, imo.
-Thanks for listening.
\ No newline at end of file +Thanks for listening.