From dc576fb0d615db3d2a4626ff3c85bcd4483d910a Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sun, 2 Aug 2015 22:47:35 +0200 Subject: [PATCH] Check if person is nil in person_image_tag closes #6286 --- Changelog.md | 1 + app/helpers/people_helper.rb | 1 + .../notifications_controller_spec.rb | 18 ++++++++++++++++++ spec/helpers/people_helper_spec.rb | 3 +++ 4 files changed, 23 insertions(+) diff --git a/Changelog.md b/Changelog.md index 3f4bdbce1..44cd69181 100644 --- a/Changelog.md +++ b/Changelog.md @@ -14,6 +14,7 @@ * Fix mobile photos index page [#6243](https://github.com/diaspora/diaspora/pull/6243) * Fix conversations view with no contacts [#6266](https://github.com/diaspora/diaspora/pull/6266) * Links in the left sidebar are now clickable on full width [#6267](https://github.com/diaspora/diaspora/pull/6267) +* Guard against passing nil into person\_image\_tag [#6286](https://github.com/diaspora/diaspora/pull/6286) ## Features diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb index e52612bf9..78b58f8fd 100644 --- a/app/helpers/people_helper.rb +++ b/app/helpers/people_helper.rb @@ -32,6 +32,7 @@ module PeopleHelper end def person_image_tag(person, size = :thumb_small) + return "" if person.nil? || person.profile.nil? image_tag(person.profile.image_url(size), :alt => person.name, :class => 'avatar', :title => person.name, 'data-person_id' => person.id) end diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index 2302320b0..7568f8e12 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -117,6 +117,24 @@ describe NotificationsController, :type => :controller do expect(assigns[:notifications].count).to eq(1) end end + + context "after deleting a person" do + before do + user = FactoryGirl.create(:user_with_aspect) + user.share_with(alice.person, user.aspects.first) + user.person.delete + end + + it "succeeds" do + get :index + expect(response).to be_success + end + + it "succeeds on mobile" do + get :index, format: :mobile + expect(response).to be_success + end + end end describe "#read_all" do diff --git a/spec/helpers/people_helper_spec.rb b/spec/helpers/people_helper_spec.rb index d127ff244..2c5f13927 100644 --- a/spec/helpers/people_helper_spec.rb +++ b/spec/helpers/people_helper_spec.rb @@ -23,6 +23,9 @@ describe PeopleHelper, :type => :helper do end describe "#person_image_tag" do + it "returns an empty string if person is nil" do + expect(person_image_tag(nil)).to eq("") + end it "should not allow basic XSS/HTML" do @person.profile.first_name = "I'm

Evil" @person.profile.last_name = "I'm

Evil"