Skip to content

Commit

Permalink
Merge pull request #3 from pipefy/bm-fix-empty-address
Browse files Browse the repository at this point in the history
Fix the name extraction when empty strings are provided
  • Loading branch information
morenobryan authored Sep 22, 2017
2 parents b1deaf8 + a23aa2f commit a05ef9f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.2
2.4.1
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ rvm:
- 2.0
- 2.1
- 2.2
- 2.4
env:
- "RAILS_BRANCH=4-1-stable"
- "RAILS_BRANCH=4-2-stable"
Expand Down
4 changes: 2 additions & 2 deletions griddler.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ Gem::Specification.new do |s|
s.homepage = 'http://thoughtbot.com'
s.summary = 'SendGrid Parse API client Rails Engine'

s.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
s.required_ruby_version = Gem::Requirement.new(">= 2.4.1")
s.files = Dir['{app,config,lib}/**/*'] + ['LICENSE', 'Rakefile', 'README.md']
s.require_paths = %w{app lib}

s.add_dependency 'rails', '>= 3.2.0'
s.add_dependency 'rails', '>= 4.2.0'
s.add_dependency 'htmlentities'
s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'sqlite3'
Expand Down
2 changes: 1 addition & 1 deletion lib/griddler/email_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def self.extract_email_address(full_address)

def self.extract_name(full_address)
full_address = full_address.strip
name = full_address.split('<').first.strip
name = full_address.split('<').first&.strip
if name.present? && name != full_address
name
end
Expand Down
17 changes: 17 additions & 0 deletions spec/griddler/email_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,23 @@ def header_from_email(header)

end

it 'handles empty names' do
email = Griddler::Email.new(
text: 'hi',
to: [' '],
from: @full_address
)
expected = {
token: nil,
host: nil,
email: '',
full: ' ',
name: nil
}
expect(email.to).to eq [expected]
expect(email.from).to eq @address_components
end

it 'returns the BCC email' do
email = Griddler::Email.new(
text: 'hi',
Expand Down

0 comments on commit a05ef9f

Please sign in to comment.