diff --git a/lib/faker/internet.rb b/lib/faker/internet.rb index 62ffc1b7e4..b47b0fc9f2 100644 --- a/lib/faker/internet.rb +++ b/lib/faker/internet.rb @@ -21,7 +21,7 @@ def safe_email(name = nil) def username(specifier = nil, separators = %w[. _]) with_locale(:en) do - return shuffle(specifier.scan(/\w+/)).join(sample(separators)).downcase if specifier.respond_to?(:scan) + return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase if specifier.respond_to?(:scan) if specifier.is_a?(Integer) # If specifier is Integer and has large value, Argument error exception is raised to overcome memory full error diff --git a/test/test_faker_internet.rb b/test/test_faker_internet.rb index ca9a7945f9..acb9948840 100644 --- a/test/test_faker_internet.rb +++ b/test/test_faker_internet.rb @@ -48,6 +48,15 @@ def test_username_with_integer_arg end end + def test_username_with_utf_8_arg + # RUBY_VERSION < '2.4.0' is not able to downcase or upcase non-ascii strings + if RUBY_VERSION < '2.4.0' + assert @tester.username('Łucja').match('Łucja') + else + assert @tester.username('Łucja').match('łucja') + end + end + def test_username_with_very_large_integer_arg exception = assert_raises(ArgumentError) { @tester.username(10_000_000) } assert_equal('Given argument is too large', exception.message)