diff --git a/lib/import/exchange/folder.rb b/lib/import/exchange/folder.rb index c442179dd..50a9d481d 100644 --- a/lib/import/exchange/folder.rb +++ b/lib/import/exchange/folder.rb @@ -43,7 +43,7 @@ module Import end def display_path(folder) - display_name = folder.display_name.utf8_encode(fallback: :read_as_sanitized_binary) + display_name = folder.display_name&.utf8_encode(fallback: :read_as_sanitized_binary) parent_folder = find(folder.parent_folder_id) return display_name if parent_folder.blank? diff --git a/spec/lib/import/exchange/folder_spec.rb b/spec/lib/import/exchange/folder_spec.rb index 3ac924fdc..97b830980 100644 --- a/spec/lib/import/exchange/folder_spec.rb +++ b/spec/lib/import/exchange/folder_spec.rb @@ -10,6 +10,20 @@ RSpec.describe Import::Exchange::Folder do let(:child_folder) { double('EWS Folder') } let(:exception_case) { double('EWS Folder') } + context 'when folder.display_name returns nil' do + before do + allow(root_folder).to receive(:display_name).and_return(nil) + allow(root_folder).to receive(:parent_folder_id).and_return(nil) + + allow(subject).to receive(:find).with(any_args).and_return(root_folder) + allow(subject).to receive(:find).with(nil).and_return(nil) + end + + it 'returns nil' do + expect(subject.display_path(root_folder)).to be(nil) + end + end + context 'when server returns valid UTF-8' do before do allow(root_folder).to receive(:display_name).and_return('Root')