Comments (18)
I just released gem version 0.1.5 with this fix and some others from yesterday!
from email_address.
Thanks again, @AlexWayfer
Like :host_remove_spaces
, there is a config for local_fix:true
which removes spaces from the local part. That default has been true since inception, but I've come around to think it should be off by default, like for the host part.
EmailAddress.error('use [email protected]', local_fix:false) #=> "Invalid Recipient/Mailbox"
2.4.1 :008 > EmailAddress.error('[email protected]', local_fix:false) #=> "Invalid Recipient/Mailbox"
2.4.1 :009 > EmailAddress.error('[email protected]', local_fix:false) #=> nil
Note that gmail local part must be in 5..64 characters long in the second example
I'll change that default to local_fix: false
and release!
from email_address.
Another example:
> EmailAddress.valid? 'user@ comversion.co m' # => true
comversion.com
exists, but comversion.co
doesn't. And spaces after @
, yeah.
from email_address.
Thanks for the report. Spaces in the domain are invalid, but the library "cleans" the address by downcasing and removing spaces from the domain. These "helpers" have been a problem before and should be opted into.
I should not "fix" the address by removing spaces unless host_remove_spaces:true
is set.
EmailAddress.new("asdf@YA hoo.com").to_s #=> "[email protected]"
EmailAddress.valid?("asdf@YA hoo.com") #=> false
EmailAddress.valid?("asdf@YA hoo.com", host_remove_spaces:true) #=> true
from email_address.
Great, thank you!
from email_address.
But why the library removes spaces? Maybe you want to use String#strip
instead of #gsub
?
from email_address.
I have noticed people leave spaces in the email address unintentionally. I have been in the habit of removing them while sanitizing input. Since .valid?() is the major use case, it shouldn't validate on any such transformations
String#strip removes spaces only at the beginning and end, while #gsub will also remove them from the middle of the string.
from email_address.
Okay, thank you.
from email_address.
Excuse me:
EmailAddress.valid? 'asdf@YA hoo.com', dns_lookup: :off # => true
EmailAddress.valid? 'asdf@YA hoo.com', dns_lookup: :off, host_remove_spaces: true # => true
EmailAddress.valid? 'asdf@YA hoo.com', dns_lookup: :off, host_remove_spaces: false # => true
😞
I think it should returns false
for any case unless host_remove_spaces
is true
.
from email_address.
I pushed a fix for this. It wasn't validating the format of the domain name without a DNS lookup. I refactored the validations to capture more errors and give more detailed error messages (though I'm not sure if that's a good thing). Do you want to verify before I release yet again? :-) PR's accepted!
from email_address.
Do you want to verify before I release yet again? :-)
Yes, I'll try it tomorrow! Thank you.
from email_address.
Yes, I'll try it tomorrow! Thank you.
Everything is fine, I guess.
PR's accepted!
PR with tests for domain_invalid
error made.
from email_address.
Oh, wait, please.
from email_address.
EmailAddress::Local.new('use r').valid? # => true
EmailAddress.valid?('use [email protected]') # => true
But here it is syntax error for use [email protected]
: "An invalid character has been detected in the provided sequence."
from email_address.
Thank you!
from email_address.
But what about default behavior for email addresses with spaces around email address parts?
pry: main > EmailAddress.valid? '[email protected]'
=> true
pry: main > EmailAddress.valid? 'user @google.com'
=> false
pry: main > EmailAddress.valid? ' [email protected]'
=> true
pry: main > EmailAddress.valid? ' user@ google.com'
=> true
pry: main > EmailAddress.valid? ' user@ google .com'
=> false
pry: main > EmailAddress.valid? ' user@ google.com '
=> true
from email_address.
I consider those as valid, just needing clean-up from forms, as everyone should be doing. Only the "inside" value is significant, like submitting a " 1 " in a numeric field. Can you imagine telling a user that their email address is wrong because there is a trailing space they can't see or understand is a problem?
You can use the .normal() method to normalize or edit the value.
EmailAddress.normal(" [email protected] ") #=> "[email protected]"
e = EmailAddress.new(" [email protected] ") #=> => #<EmailAddress::Address:....>
e.normal #=> "[email protected]"
e.valid? #=> true
from email_address.
Oh, I just saw "user@ google.com" ... not outright wrong, just inconsistent. I'll think about it.
from email_address.
Related Issues (20)
- Still making DNS requests when `dns_lookup` is `off` HOT 3
- Dots in a GSuite domain are not the same as in gmail HOT 2
- EmailAddress validation fail with dns_lookup HOT 1
- Address validation `address_local` not implemented HOT 1
- Period not allowed in tags? HOT 2
- Ruby 3.0.0 deprecation: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead HOT 1
- Tests fails on current `master` HOT 1
- Go to another CI HOT 1
- Validating common email typos without MX/network lookup, using public suffix gem HOT 1
- EmailAddress.matches?(address, 'google') #=> 'google' (true) Error in Version 0.1.20 HOT 1
- Relaxed is not accepting + character HOT 2
- DNS MX timeout - no error HOT 1
- Valid google emails marked as invalid HOT 4
- Valid google address has too short local part HOT 1
- net-smtp gem required with Ruby >= 3.1 HOT 1
- :host_size is Unresponsive
- syntax error, unexpected '.' (SyntaxError) HOT 1
- Gmail address validation on old addresses HOT 2
- Seemingly valid email address marked invalid HOT 5
- Canonical does not remove . HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from email_address.