From 36dc5874e55e34d2fff65e448e1ddcfcc6fe4b17 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Thu, 11 Apr 2013 12:36:45 -0400 Subject: [PATCH] Post image_count doesn't count favicons and thumbnails in oneboxes, so visitors can post links that get oneboxed --- app/models/post.rb | 2 +- spec/models/post_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/post.rb b/app/models/post.rb index 2e976938c65..b4441f17efe 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -90,7 +90,7 @@ class Post < ActiveRecord::Base end def self.white_listed_image_classes - @white_listed_image_classes ||= ['avatar'] + @white_listed_image_classes ||= ['avatar', 'favicon', 'thumbnail'] end def image_count diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 91758c8d3df..805b7428085 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -88,6 +88,8 @@ describe Post do let(:post_one_image) { Fabricate.build(:post, post_args.merge(raw: "![sherlock](http://bbc.co.uk/sherlock.jpg)", user: visitor)) } let(:post_two_images) { Fabricate.build(:post, post_args.merge(raw: " ", user: visitor)) } let(:post_with_avatars) { Fabricate.build(:post, post_args.merge(raw: 'smiley wink', user: visitor)) } + let(:post_with_favicon) { Fabricate.build(:post, post_args.merge(raw: '', user: visitor)) } + let(:post_with_thumbnail) { Fabricate.build(:post, post_args.merge(raw: '', user: visitor)) } let(:post_with_two_classy_images) { Fabricate.build(:post, post_args.merge(raw: " ", user: visitor)) } it "returns 0 images for an empty post" do @@ -106,6 +108,14 @@ describe Post do post_with_avatars.image_count.should == 0 end + it "doesn't count favicons as images" do + post_with_favicon.image_count.should == 0 + end + + it "doesn't count thumbnails as images" do + post_with_thumbnail.image_count.should == 0 + end + it "doesn't count whitelisted images" do Post.stubs(:white_listed_image_classes).returns(["classy"]) post_with_two_classy_images.image_count.should == 0