emoji icon indicating copy to clipboard operation
emoji copied to clipboard

Fix edge cases in replace_emoji, demojize, and version functions

Open sunnynguyen-ai opened this issue 3 months ago • 0 comments

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.

sunnynguyen-ai avatar Sep 26 '25 19:09 sunnynguyen-ai