Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Faker::Internet.username should not generate duplicated punctuation #2970

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/faker/default/internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def username(specifier: nil, separators: %w[. _])
with_locale(:en) do
case specifier
when ::String
names = specifier&.gsub("'", '')&.split
names = specifier.gsub("'", '').scan(/[[:word:]]+/)
shuffled_names = shuffle(names)

return shuffled_names.join(sample(separators)).downcase
Expand Down
16 changes: 16 additions & 0 deletions test/faker/default/test_faker_internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ def test_email_with_apostrophes
end
end

def test_email_with_abbreviations
name = 'Mr. Faker'

deterministically_verify -> { @tester.email(name: name) } do |email|
assert_email_regex 'Mr', 'Faker', email
end
end

def test_email_against_name_generator
deterministically_verify -> { @tester.email(name: Faker::Name.unique.name) } do |email|
# reject emails with duplicated punctuation
# e.g.: "[email protected]"
refute_match(/[\p{Punct}]{2,}/, email)
end
end

def test_email_with_separators
deterministically_verify -> { @tester.email(name: 'jane doe', separators: '+') } do |result|
name, domain = result.split('@')
Expand Down
Loading