Merge remote-tracking branch 'origin/analyze-code-fix'

This commit is contained in:
Robin Ward 2018-03-06 13:16:37 -05:00
commit 81780d8607
2 changed files with 23 additions and 2 deletions

View File

@ -130,7 +130,7 @@ class PostAnalyzer
def cooked_stripped def cooked_stripped
@cooked_stripped ||= begin @cooked_stripped ||= begin
doc = Nokogiri::HTML.fragment(cook(@raw, topic_id: @topic_id)) doc = Nokogiri::HTML.fragment(cook(@raw, topic_id: @topic_id))
doc.css("pre, code, aside.quote > .title, aside.quote .mention, .onebox, .elided").remove doc.css("pre .mention, aside.quote > .title, aside.quote .mention, .onebox, .elided").remove
doc doc
end end
end end

View File

@ -170,6 +170,8 @@ describe Post do
let(:post_with_avatars) { post_with_body('<img alt="smiley" title=":smiley:" src="/assets/emoji/smiley.png" class="avatar"> <img alt="wink" title=":wink:" src="/assets/emoji/wink.png" class="avatar">', newuser) } let(:post_with_avatars) { post_with_body('<img alt="smiley" title=":smiley:" src="/assets/emoji/smiley.png" class="avatar"> <img alt="wink" title=":wink:" src="/assets/emoji/wink.png" class="avatar">', newuser) }
let(:post_with_favicon) { post_with_body('<img src="/assets/favicons/wikipedia.png" class="favicon">', newuser) } let(:post_with_favicon) { post_with_body('<img src="/assets/favicons/wikipedia.png" class="favicon">', newuser) }
let(:post_image_within_quote) { post_with_body('[quote]<img src="coolimage.png">[/quote]', newuser) } let(:post_image_within_quote) { post_with_body('[quote]<img src="coolimage.png">[/quote]', newuser) }
let(:post_image_within_code) { post_with_body('<code><img src="coolimage.png"></code>', newuser) }
let(:post_image_within_pre) { post_with_body('<pre><img src="coolimage.png"></pre>', newuser) }
let(:post_with_thumbnail) { post_with_body('<img src="/assets/emoji/smiley.png" class="thumbnail">', newuser) } let(:post_with_thumbnail) { post_with_body('<img src="/assets/emoji/smiley.png" class="thumbnail">', newuser) }
let(:post_with_two_classy_images) { post_with_body("<img src='http://discourse.org/logo.png' class='classy'> <img src='http://bbc.co.uk/sherlock.jpg' class='classy'>", newuser) } let(:post_with_two_classy_images) { post_with_body("<img src='http://discourse.org/logo.png' class='classy'> <img src='http://bbc.co.uk/sherlock.jpg' class='classy'>", newuser) }
@ -199,12 +201,24 @@ describe Post do
expect(post_one_image).not_to be_valid expect(post_one_image).not_to be_valid
end end
it "doesn't allow more than `min_trust_to_post_images`" do it "doesn't allow more than `min_trust_to_post_images` in a quote" do
SiteSetting.min_trust_to_post_images = 4 SiteSetting.min_trust_to_post_images = 4
post_one_image.user.trust_level = 3 post_one_image.user.trust_level = 3
expect(post_image_within_quote).not_to be_valid expect(post_image_within_quote).not_to be_valid
end end
it "doesn't allow more than `min_trust_to_post_images` in code" do
SiteSetting.min_trust_to_post_images = 4
post_one_image.user.trust_level = 3
expect(post_image_within_code).not_to be_valid
end
it "doesn't allow more than `min_trust_to_post_images` in pre" do
SiteSetting.min_trust_to_post_images = 4
post_one_image.user.trust_level = 3
expect(post_image_within_pre).not_to be_valid
end
it "doesn't allow more than `min_trust_to_post_images`" do it "doesn't allow more than `min_trust_to_post_images`" do
SiteSetting.min_trust_to_post_images = 4 SiteSetting.min_trust_to_post_images = 4
post_one_image.user.trust_level = 4 post_one_image.user.trust_level = 4
@ -379,6 +393,7 @@ describe Post do
let(:newuser) { Fabricate(:user, trust_level: TrustLevel[0]) } let(:newuser) { Fabricate(:user, trust_level: TrustLevel[0]) }
let(:post_one_link) { post_with_body("[sherlock](http://www.bbc.co.uk/programmes/b018ttws)", newuser) } let(:post_one_link) { post_with_body("[sherlock](http://www.bbc.co.uk/programmes/b018ttws)", newuser) }
let(:post_onebox) { post_with_body("http://www.google.com", newuser) } let(:post_onebox) { post_with_body("http://www.google.com", newuser) }
let(:post_code_link) { post_with_body("<code>http://www.google.com</code>", newuser) }
let(:post_two_links) { post_with_body("<a href='http://discourse.org'>discourse</a> <a href='http://twitter.com'>twitter</a>", newuser) } let(:post_two_links) { post_with_body("<a href='http://discourse.org'>discourse</a> <a href='http://twitter.com'>twitter</a>", newuser) }
let(:post_with_mentions) { post_with_body("hello @#{newuser.username} how are you doing?", newuser) } let(:post_with_mentions) { post_with_body("hello @#{newuser.username} how are you doing?", newuser) }
@ -427,6 +442,12 @@ describe Post do
expect(post_onebox).not_to be_valid expect(post_onebox).not_to be_valid
end end
it "considers links within code" do
SiteSetting.min_trust_to_post_links = 3
post_onebox.user.trust_level = TrustLevel[2]
expect(post_code_link).not_to be_valid
end
it "doesn't allow allow links if `min_trust_to_post_links` is not met" do it "doesn't allow allow links if `min_trust_to_post_links` is not met" do
SiteSetting.min_trust_to_post_links = 2 SiteSetting.min_trust_to_post_links = 2
post_two_links.user.trust_level = TrustLevel[1] post_two_links.user.trust_level = TrustLevel[1]