diff --git a/Changelog.md b/Changelog.md index 785e3aa08..7559b454b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -27,6 +27,7 @@ * Fix inactive user removal not respecting configuration for daily limits [#5953](https://github.com/diaspora/diaspora/pull/5953) * Fix missing localization of inactive user removal warning emails [#5950](https://github.com/diaspora/diaspora/issues/5950) * Fix fetching for public post while Webfingering [#5958](https://github.com/diaspora/diaspora/pull/5958) +* Handle empty searchable in HCard gracefully [#5962](https://github.com/diaspora/diaspora/pull/5962) ## Features * Hide post title of limited post in comment notification email [#5843](https://github.com/diaspora/diaspora/pull/5843) diff --git a/lib/h_card.rb b/lib/h_card.rb index 753c023f0..2fda6aa2e 100644 --- a/lib/h_card.rb +++ b/lib/h_card.rb @@ -3,19 +3,19 @@ # the COPYRIGHT file. module HCard - def self.parse doc + def self.parse(doc) { - :given_name => doc.css(".given_name").text, - :family_name => doc.css(".family_name").text, - :url => doc.css("#pod_location").text, - :photo => doc.css(".entity_photo .photo[src]").attribute('src').text, - :photo_small => doc.css(".entity_photo_small .photo[src]").attribute('src').text, - :photo_medium => doc.css(".entity_photo_medium .photo[src]").attribute('src').text, - :searchable => doc.css(".searchable").text + given_name: doc.css(".given_name").text, + family_name: doc.css(".family_name").text, + url: doc.css("#pod_location").text, + photo: doc.css(".entity_photo .photo[src]").attribute("src").text, + photo_small: doc.css(".entity_photo_small .photo[src]").attribute("src").text, + photo_medium: doc.css(".entity_photo_medium .photo[src]").attribute("src").text, + searchable: doc.css(".searchable").text == "true" } end def self.build(raw_hcard) - self.parse Nokogiri::HTML(raw_hcard) + parse Nokogiri::HTML(raw_hcard) end end diff --git a/spec/lib/h_card_spec.rb b/spec/lib/h_card_spec.rb new file mode 100644 index 000000000..d4197c0b4 --- /dev/null +++ b/spec/lib/h_card_spec.rb @@ -0,0 +1,43 @@ +# Copyright (c) 2010-2011, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require "spec_helper" + +describe HCard do + it "should parse an hcard" do + raw_hcard = hcard_response + hcard = HCard.build raw_hcard + expect(hcard[:family_name].include?("Hamiltom")).to be true + expect(hcard[:given_name].include?("Alex")).to be true + expect(hcard[:photo].include?("thumb_large")).to be true + expect(hcard[:photo_medium].include?("thumb_medium")).to be true + expect(hcard[:photo_small].include?("thumb_small")).to be true + expect(hcard[:url]).to eq("http://localhost:3000/") + expect(hcard[:searchable]).to eq(false) + end + + it "should parse an hcard with searchable true" do + raw_hcard = hcard_response.sub("false", "true") + hcard = HCard.build raw_hcard + expect(hcard[:family_name].include?("Hamiltom")).to be true + expect(hcard[:given_name].include?("Alex")).to be true + expect(hcard[:photo].include?("thumb_large")).to be true + expect(hcard[:photo_medium].include?("thumb_medium")).to be true + expect(hcard[:photo_small].include?("thumb_small")).to be true + expect(hcard[:url]).to eq("http://localhost:3000/") + expect(hcard[:searchable]).to eq(true) + end + + it "should parse an hcard with empty searchable" do + raw_hcard = hcard_response.sub("false", "") + hcard = HCard.build raw_hcard + expect(hcard[:family_name].include?("Hamiltom")).to be true + expect(hcard[:given_name].include?("Alex")).to be true + expect(hcard[:photo].include?("thumb_large")).to be true + expect(hcard[:photo_medium].include?("thumb_medium")).to be true + expect(hcard[:photo_small].include?("thumb_small")).to be true + expect(hcard[:url]).to eq("http://localhost:3000/") + expect(hcard[:searchable]).to eq(false) + end +end diff --git a/spec/lib/hcard_spec.rb b/spec/lib/hcard_spec.rb deleted file mode 100644 index 86cab268b..000000000 --- a/spec/lib/hcard_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require 'spec_helper' - -describe HCard do - it 'should parse an hcard' do - raw_hcard = hcard_response - hcard = HCard.build raw_hcard - expect(hcard[:family_name].include?("Hamiltom")).to be true - expect(hcard[:given_name].include?("Alex")).to be true - expect(hcard[:photo].include?("thumb_large")).to be true - expect(hcard[:photo_medium].include?("thumb_medium")).to be true - expect(hcard[:photo_small].include?("thumb_small")).to be true - expect(hcard[:url]).to eq("http://localhost:3000/") - expect(hcard[:searchable]).to eq("false") - end -end