Fix edge cases in replace_emoji, demojize, and version functions#324
Open
sunnynguyen-ai wants to merge 2 commits intocarpedm20:masterfrom
Open
Fix edge cases in replace_emoji, demojize, and version functions#324sunnynguyen-ai wants to merge 2 commits intocarpedm20:masterfrom
sunnynguyen-ai wants to merge 2 commits intocarpedm20:masterfrom
Conversation
added 2 commits
September 26, 2025 12:50
The replace_emoji() function was not properly handling empty string
replacements due to a falsy check. When replace="" (the default),
the function would skip replacement and return the original emoji
instead of removing it.
Changed the logic from checking "replace is not None" to always
applying str(replace), which correctly handles empty strings and
other edge cases.
Fixes issue where emoji.replace_emoji("Hello 👋", replace="")
would return "Hello 👋" instead of "Hello ".
- Fix replace_emoji() to properly handle empty string replacements
- Add bounds checking for alias processing in demojize()
- Use safe key access for emoji version data in version()
- Prevent IndexError and KeyError on malformed emoji data
Fixes:
- emoji.replace_emoji("Hello 👋", replace="") now returns "Hello "
- demojize() no longer crashes on empty/short aliases
- version() handles missing 'E' key gracefully
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes several edge cases and improves error handling in core emoji functions:
Fixes:
emoji.replace_emoji("Hello 👋", replace="")now correctly returns "Hello "demojize()no longer crashes on empty/short aliasesversion()handles missing 'E' key gracefullyThese changes improve the library's robustness when handling edge cases and malformed data.