From cebd80867438c22d5c98fc4cfbb9e347c475b72b Mon Sep 17 00:00:00 2001 From: erwanlr Date: Fri, 15 Aug 2014 22:54:17 +0200 Subject: [PATCH] Ensures a nil location is not processed when enumerating usernames --- lib/common/models/wp_user/existable.rb | 2 ++ spec/shared_examples/wp_user/existable.rb | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/common/models/wp_user/existable.rb b/lib/common/models/wp_user/existable.rb index 7d547017..30603748 100755 --- a/lib/common/models/wp_user/existable.rb +++ b/lib/common/models/wp_user/existable.rb @@ -22,6 +22,8 @@ class WpUser < WpItem if response.code == 301 # login in location? location = response.headers_hash['Location'] + return unless location + @login = Existable.login_from_author_pattern(location) @display_name = Existable.display_name_from_body( Browser.get(location).body diff --git a/spec/shared_examples/wp_user/existable.rb b/spec/shared_examples/wp_user/existable.rb index e36327a0..5803a98d 100644 --- a/spec/shared_examples/wp_user/existable.rb +++ b/spec/shared_examples/wp_user/existable.rb @@ -124,6 +124,15 @@ shared_examples 'WpUser::Existable' do @login = 'admin' @display_name = 'admin name' end + + context 'when the location is nil' do + let(:location) { nil } + + it 'returns nil' do + @login = nil + @display_name = nil + end + end end context 'with a 200' do