Code Monkey home page Code Monkey logo

Comments (18)

afair avatar afair commented on September 26, 2024 1

I just released gem version 0.1.5 with this fix and some others from yesterday!

from email_address.

afair avatar afair commented on September 26, 2024 1

Thanks again, @AlexWayfer

Like :host_remove_spaces, there is a config for local_fix:truewhich 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.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

Another example:

> EmailAddress.valid? 'user@            comversion.co m' # => true

comversion.com exists, but comversion.co doesn't. And spaces after @, yeah.

from email_address.

afair avatar afair commented on September 26, 2024

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.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

Great, thank you!

from email_address.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

But why the library removes spaces? Maybe you want to use String#strip instead of #gsub?

from email_address.

afair avatar afair commented on September 26, 2024

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.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

Okay, thank you.

from email_address.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

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.

afair avatar afair commented on September 26, 2024

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.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

Do you want to verify before I release yet again? :-)

Yes, I'll try it tomorrow! Thank you.

from email_address.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

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.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

Oh, wait, please.

from email_address.

AlexWayfer avatar AlexWayfer commented on September 26, 2024
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.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

Thank you!

from email_address.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

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.

afair avatar afair commented on September 26, 2024

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.

afair avatar afair commented on September 26, 2024

Oh, I just saw "user@ google.com" ... not outright wrong, just inconsistent. I'll think about it.

from email_address.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.