Skip to content

Trie.deleteWord fails for words containing characters outside the BMP (e.g. emoji) #2237

Open

Description

@devladpopov

addWord iterates with Array.from(word) (code points), but deleteWord (lines 33, 38, 50) uses word[i] and word.length (UTF-16 code units). It looks up a lone surrogate, finds no child, and returns without deleting.

trie.addWord('😀');
trie.deleteWord('😀');
trie.doesWordExist('😀');  // true   expected false

Fix: use Array.from(word) in deleteWord too.


Found during an independent property-based audit of this repo (full report and reproducible harness: https://github.com/devladpopov/algorithm-autopsy/tree/main/autopsy-02).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions