Git Product home page Git Product logo

Comments (8)

keshavbiswa avatar keshavbiswa commented on June 5, 2024

So currently when we run

Faker::Internet.email(name: "Alexis O'MConnell")

#=> [email protected]

This might not be what we expect. But I'm not sure what is the correct representation for this?

from faker.

keshavbiswa avatar keshavbiswa commented on June 5, 2024

Is it [email protected]?

from faker.

alextaujenis avatar alextaujenis commented on June 5, 2024

@keshavbiswa exactly...

So this generator will return all of these possible permutations of the username:

and the test regex is only validating these possibilities:

Here is the relevant code that generates these values within Faker::Internet.email (code edited below for brevity):

  def email(name: nil, separators: nil, domain: nil)
    local_part = username(specifier: name, separators: separators)
    generate_domain = domain_name(domain: domain)
    return [local_part, generate_domain].join('@')
  end

  def username(specifier: nil, separators: %w[. _])
    return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase
  end

What's happening here is that Faker::Internet.email will accept a name and split the string attempting to find the different parts, shuffle the different parts, then join them back together with a random separator of a period or underscore. The issue is the apostrophe in O'Connell being treated as a word separator and the O is being independently shuffled as part of the username.

This issue has what appears to be several cascading problems that could be solved different ways:

  1. An apostrophe is valid within an email address, so this generator could be adjusted to keep O'Connell together and not shuffle the O within the username, then adjust the email_regex to accommodate. This would allow the test to still verify the provided username and returned email address without stripping the apostrophe.

  2. The email_regex could be adjusted to just verify ANY valid email address instead of all possible [email protected] permutations. However, this would reduce the test suites ability to detect the expected outcome of including the user's full name within the generated email address.

  3. Strip the apostrophe from the last name within the test suite and just return permutations of [email protected]. This will still shuffle last names with an apostrophe when they are provided in real-world scenarios.

from faker.

keshavbiswa avatar keshavbiswa commented on June 5, 2024

@keshavbiswa exactly...

So this generator will return all of these possible permutations of the username:

and the test regex is only validating these possibilities:

Here is the relevant code that generates these values within Faker::Internet.email (code edited below for brevity):

  def email(name: nil, separators: nil, domain: nil)
    local_part = username(specifier: name, separators: separators)
    generate_domain = domain_name(domain: domain)
    return [local_part, generate_domain].join('@')
  end

  def username(specifier: nil, separators: %w[. _])
    return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase
  end

What's happening here is that Faker::Internet.email will accept a name and split the string attempting to find the different parts, shuffle the different parts, then join them back together with a random separator of a period or underscore. The issue is the apostrophe in O'Connell being treated as a word separator and the O is being independently shuffled as part of the username.

This issue has what appears to be several cascading problems that could be solved different ways:

  1. An apostrophe is valid within an email address, so this generator could be adjusted to keep O'Connell together and not shuffle the O within the username, then adjust the email_regex to accommodate. This would allow the test to still verify the provided username and returned email address without stripping the apostrophe.
  2. The email_regex could be adjusted to just verify ANY valid email address instead of all possible [email protected] permutations. However, this would reduce the test suites ability to detect the expected outcome of including the user's full name within the generated email address.
  3. Strip the apostrophe from the last name within the test suite and just return permutations of [email protected]. This will still shuffle last names with an apostrophe when they are provided in real-world scenarios.

I think I'll try the 3rd approach, although apostrophe's are valid, it might still look weird for others, so maybe it's best to keep it simple? Also like you mentioned, it might not be a good idea to verify just any valid email address.

from faker.

keshavbiswa avatar keshavbiswa commented on June 5, 2024

On second thought, I feel even the 3rd approach might not be a good idea since we're not covering all the scenarios. Maybe we keep the apostrophe together, do we want [email protected], seems incorrect to me.

from faker.

stefannibrasil avatar stefannibrasil commented on June 5, 2024

Oh, this is an interesting issue. An apostrophe is not a valid character per Google so I don't think it makes sense keeping it around for the email.

I think it makes sense to just drop the apostrophe when generating the email address and merge it into the last name. Although we could use ., I don't think it would make sense to split it out of the last name. So dropping it and merging it with the last name seems to be the simplest approach to take. So the only permutations would be:

from faker.

alextaujenis avatar alextaujenis commented on June 5, 2024

@stefannibrasil It is completely valid to include an apostrophe within an email address and I'd suggest keeping this character within the Faker email generator. I'd suggest that it's important to guide these decisions based upon the IETF RFC standards.

If you strip out the apostrophe you will still have to accommodate for random test failures when checking with the current Omniauth regex:

  def email_regex(first_name, last_name)
    /(#{first_name}(.|_)#{last_name}|#{last_name}(.|_)#{first_name})@(.*).(example|test)/i
  end

You can get around this issue by also stripping apostrophes from the first and last names within the test data, but generally speaking I think it's an easier fix to include the apostrophe instead of stripping it. Keeping the apostrophe and fixing the broken test seems to be as simple as replacing specifier.scan(/[[:word:]]+/) with specifier.split within the Faker::Internet.username method.

from faker.

stefannibrasil avatar stefannibrasil commented on June 5, 2024

Ah, thank you! I was mainly concerned about separating the apostrophe from the last name but confirmed that is handled in the linked PR.

from faker.

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.