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::Number.hexadecimal should include characters within the range of [0-9a-f] #2942

Merged
merged 2 commits into from Apr 28, 2024

Conversation

alextaujenis
Copy link
Contributor

Motivation / Background

This Pull Request has been created because Faker::Number.hexadecimal returns characters within the range of [0-9a-e], when it should return characters within the range of [0-9a-f]. The method is not producing the f character within the generated hexadecimal strings.

Additional Information

def hexadecimal(digits: 6)
  hex = ''
  digits.times { hex += rand(15).to_s(16) }
  hex
end

The current implementation (above) includes rand(15), which is not inclusive and only returns the range [0-14], when the implementation requires [0-15] in order to return the f character. Adjusting the current implementation to return rand(16).to_s(16) allows the Faker::Number.hexadecimal method to return strings within the full character range (including the letter f, which is equal to 15.to_s(16)).

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug, refactor something, or add a feature.
  • Tests and Rubocop are passing before submitting your proposed changes.
  • Double-check the existing generators documentation to make sure the new generator you want to add doesn't already exist.
  • You've reviewed and followed the Contributing guidelines.

@@ -114,7 +114,7 @@ def digit
# @faker.version 1.0.0
def hexadecimal(digits: 6)
hex = ''
digits.times { hex += rand(15).to_s(16) }
digits.times { hex += rand(16).to_s(16) }
Copy link
Contributor

Choose a reason for hiding this comment

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

nice catch!

@thdaraujo thdaraujo changed the title Fix: Include 'f' character within Faker::Number.hexadecimal Fix: Faker::Number.hexadecimal should include characters in the range (0..'f') Apr 28, 2024
@thdaraujo thdaraujo changed the title Fix: Faker::Number.hexadecimal should include characters in the range (0..'f') Fix: Faker::Number.hexadecimal should include characters between 0 and f Apr 28, 2024
@thdaraujo thdaraujo changed the title Fix: Faker::Number.hexadecimal should include characters between 0 and f Fix: Faker::Number.hexadecimal should include characters within the range of [0-9a-f] Apr 28, 2024
@thdaraujo thdaraujo merged commit 74b2a7f into faker-ruby:main Apr 28, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants