-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Add non-ASCII character check for username suggestions #36056
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
Add non-ASCII character check for username suggestions #36056
Conversation
Thanks for the pull request, @CodeWithEmad! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. Where can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
59b463c
to
111c5d3
Compare
Sorry to ping you here @kdmccormick but I noticed that it takes about 20-25 minutes to run all the lint/test jobs and lining is a big chunk of it (about 10-12 minutes!). Pylint is so slow and as the project grows, it takes more time just to check the linting and code style! Have we ever considered using ruff? |
111c5d3
to
1ceffb5
Compare
Hi @CodeWithEmad! Just checking to see if this is still in progress? |
Hey @mphilbrick211 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this is a bugfix, I think it does not need product review. Please rebase and confirm that the feature works as expected on the PR sandbox (which should spin up within an hour). Please also change your commit message to fix:
, since we are fixing an active bug rather than adding a new feature.
Thank you for finding and resolving this!
def generate_username_suggestions(name: str) -> list[str] | list: | ||
""" | ||
Generate 3 available username suggestions based on the provided name. | ||
|
||
Args: | ||
name (str): The full name to generate username suggestions from. | ||
Must contain only ASCII characters. | ||
|
||
Returns: | ||
list[str] | list: A list of up to 3 available username suggestions, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An empty list is a valid list[str]
(because it vacuously it satisfies the predicate "every item in the list is a string"), so there is no need to specify | list
. In fact, it is preferable to omit | list
, because list[str] | list
would allow for lists of integers, booleans, or any other type.
def generate_username_suggestions(name: str) -> list[str] | list: | |
""" | |
Generate 3 available username suggestions based on the provided name. | |
Args: | |
name (str): The full name to generate username suggestions from. | |
Must contain only ASCII characters. | |
Returns: | |
list[str] | list: A list of up to 3 available username suggestions, | |
def generate_username_suggestions(name: str) -> list[str]: | |
""" | |
Generate 3 available username suggestions based on the provided name. | |
Args: | |
name (str): The full name to generate username suggestions from. | |
Must contain only ASCII characters. | |
Returns: | |
list[str]: A list of up to 3 available username suggestions, |
# Test normal ASCII name | ||
('John Doe', True), # Should return suggestions | ||
('Jane Smith', True), # Should return suggestions | ||
# Test non-ASCII names | ||
('José García', False), # Contains non-ASCII characters | ||
('مریم میرزاخانی', False), # Persian name | ||
('明美 田中', False), # Japanese name | ||
('Σωκράτης', False), # Greek name | ||
('Владимир', False), # Cyrillic characters | ||
# Test edge cases | ||
('A B', True), # Minimal valid name | ||
('', True), # Empty string | ||
(' ', True), # Just spaces |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌🏻
Sandbox deployment successful 🚀 |
@CodeWithEmad ^ username/password for the sandbox is openedx/openedx |
… detailed docstring - Updated `generate_username_suggestions` function to include validation for non-ASCII characters. - Improved function documentation to clarify arguments, return types, and username generation logic. - Added type hints for better code clarity and maintainability.
- Introduced `remove_special_characters_from_name` and `generate_username_suggestions` functions to enhance username handling. - Added comprehensive test cases for username generation, including ASCII validation and uniqueness checks. - Implemented tests for special character removal and suggestion generation based on various input scenarios, including edge cases.
- Removed unnecessary blank lines in the add-remove-label-on-comment.yml and check_python_dependencies.yml files to improve readability and maintainability.
1ceffb5
to
54ef475
Compare
Thank you, dear @kdmccormick. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent! I'll merge tomorrow.
Sandbox deployment successful 🚀 |
2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production. |
2U Release Notice: This PR has been deployed to the edX production environment. |
2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production. |
2U Release Notice: This PR has been deployed to the edX production environment. |
Added validation to prevent generating username suggestions for names containing non-ASCII characters. This fixes an issue where the system would generate usernames containing non-ASCII characters that would later be rejected by username validation.
Changes include:
generate_username_suggestions
Testing
TestUsernameGeneration
with test cases for:Close #35984