Skip to content

swap_case doesn't correctly handle non-ASCII letters #3847

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

Closed
frankschmitt opened this issue Oct 31, 2020 · 0 comments · Fixed by #3848
Closed

swap_case doesn't correctly handle non-ASCII letters #3847

frankschmitt opened this issue Oct 31, 2020 · 0 comments · Fixed by #3848

Comments

@frankschmitt
Copy link
Contributor

The strings/swap_case implementation works only for ASCII letters (since it uses the incomplete regex [^a-zA-Z] to check whether a given characters is a letter). If you provide it with a non-ASCII letter, it will happily swap it and also return the unchanged version.

Example:

➜ strings git:(master) python3 swap_case.py
Please input sentence:This is broken: äü
tHIS IS BROKEN: ÄäÜü

The solution is pretty straightforward - it shouldn't use a regular expression at all, but rely on the built-in Python functions (as it partially already does).

frankschmitt added a commit to frankschmitt/Python that referenced this issue Oct 31, 2020
frankschmitt added a commit to frankschmitt/Python that referenced this issue Oct 31, 2020
frankschmitt added a commit to frankschmitt/Python that referenced this issue Nov 2, 2020
@dhruvmanila dhruvmanila linked a pull request Nov 6, 2020 that will close this issue
14 tasks
dhruvmanila added a commit that referenced this issue Nov 6, 2020
* #3847 fix handling of non-ASCII characters in swap_case

* #3847 remove unused regex

* Fix formatting (with black) Fixes: #3847

* Add type hints for `swap_case` function

Co-authored-by: Frank Schmitt <[email protected]>
Co-authored-by: Dhruv Manilawala <[email protected]>
stokhos pushed a commit to stokhos/Python that referenced this issue Jan 3, 2021
…ms#3847) (TheAlgorithms#3848)

* TheAlgorithms#3847 fix handling of non-ASCII characters in swap_case

* TheAlgorithms#3847 remove unused regex

* Fix formatting (with black) Fixes: TheAlgorithms#3847

* Add type hints for `swap_case` function

Co-authored-by: Frank Schmitt <[email protected]>
Co-authored-by: Dhruv Manilawala <[email protected]>
peRFectBeliever pushed a commit to peRFectBeliever/Python that referenced this issue Apr 1, 2021
…ms#3847) (TheAlgorithms#3848)

* TheAlgorithms#3847 fix handling of non-ASCII characters in swap_case

* TheAlgorithms#3847 remove unused regex

* Fix formatting (with black) Fixes: TheAlgorithms#3847

* Add type hints for `swap_case` function

Co-authored-by: Frank Schmitt <[email protected]>
Co-authored-by: Dhruv Manilawala <[email protected]>
Panquesito7 pushed a commit to Panquesito7/Python that referenced this issue May 13, 2021
…ms#3847) (TheAlgorithms#3848)

* TheAlgorithms#3847 fix handling of non-ASCII characters in swap_case

* TheAlgorithms#3847 remove unused regex

* Fix formatting (with black) Fixes: TheAlgorithms#3847

* Add type hints for `swap_case` function

Co-authored-by: Frank Schmitt <[email protected]>
Co-authored-by: Dhruv Manilawala <[email protected]>
shermanhui pushed a commit to shermanhui/Python that referenced this issue Oct 22, 2021
…ms#3847) (TheAlgorithms#3848)

* TheAlgorithms#3847 fix handling of non-ASCII characters in swap_case

* TheAlgorithms#3847 remove unused regex

* Fix formatting (with black) Fixes: TheAlgorithms#3847

* Add type hints for `swap_case` function

Co-authored-by: Frank Schmitt <[email protected]>
Co-authored-by: Dhruv Manilawala <[email protected]>
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 a pull request may close this issue.

1 participant