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

Faker::Internet.user_name can't handle UTF-8 arguments #1421

Merged
merged 7 commits into from Oct 19, 2018
Merged

Faker::Internet.user_name can't handle UTF-8 arguments #1421

merged 7 commits into from Oct 19, 2018

Conversation

ivanoblomov
Copy link
Contributor

@ivanoblomov ivanoblomov commented Oct 18, 2018

Because the \w character class is exactly equivalent to [A-Za-z0-9_], we need [[:word:]] to support UTF-8.

Fixes #168.

@ivanoblomov
Copy link
Contributor Author

@vbrazo, would you know why CI is failing for ruby 2.4.4 and 2.5.1? The patch seems to work correctly locally for both versions.

@@ -48,6 +48,10 @@ def test_username_with_integer_arg
end
end

def test_username_with_utf_8_arg
assert @tester.username('Łucja').match('Łucja')
end
Copy link
Member

@vbrazo vbrazo Oct 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your solution looks good. What's killing you is the .downcase at the end of the shuffle method: return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase if specifier.respond_to?(:scan)

From: /faker-ruby/faker/test/test_faker_internet.rb @ line 53 TestFakerInternet#test_username_with_utf_8_arg:

    51: def test_username_with_utf_8_arg
    52:   require 'pry'
 => 53:   binding.pry
    54:   assert @tester.username('Łucja').match('Łucja')
    55: end

[1] pry(#<TestFakerInternet>)> @tester.username('Łucja')
=> "łucja"

@vbrazo
Copy link
Member

vbrazo commented Oct 19, 2018

Now ruby 2.4.4 and 2.5.1 are working and ruby 2.3.7 stopped working 😆

Let me investigate a bit more.

@vbrazo
Copy link
Member

vbrazo commented Oct 19, 2018

@ivanoblomov I know what it is. Ruby 2.3.7 isn't able to convert Łucja/non-ascii strings to downcase. If you try to use .downcase, it'll return the string that you passed without changing it. That's why the test fails - Reference.

Let me know what you think.

@ivanoblomov
Copy link
Contributor Author

Nice catch @vbrazo, thanks!

@vbrazo vbrazo merged commit 32891c4 into faker-ruby:master Oct 19, 2018
@ivanoblomov ivanoblomov deleted the fix-utf8-bug branch October 31, 2018 17:55
davidmorton0 pushed a commit to davidmorton0/faker that referenced this pull request Jul 12, 2021
* test: covered bug

* fix: passed

* fix: typo

* Minor fix

* Fix test_username_with_utf_8_arg - Faker::Internet.user_name

* Add comment above test_username_with_utf_8_arg

* Update test_faker_internet.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants