Skip to content

Conversation

@sunnynguyen-ai
Copy link

This PR fixes several edge cases and improves error handling in core emoji functions:

  • Add bounds checking for alias processing in demojize() - Prevents IndexError when alias list is empty or aliases are too short
  • Use safe key access for emoji version data in version() - Handles missing 'E' key gracefully with default value
  • Prevent IndexError and KeyError on malformed emoji data - Makes functions more robust against corrupted data

Fixes:

  • emoji.replace_emoji("Hello 👋", replace="") now correctly returns "Hello "
  • demojize() no longer crashes on empty/short aliases
  • version() handles missing 'E' key gracefully

These changes improve the library's robustness when handling edge cases and malformed data.

Sunny Nguyen 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
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.

1 participant