The vulnerability exists in the htmlEscaped function within the leaf-kit library. The root cause is the incorrect use of string replacement functions (replacing and replacingOccurrences) that operate on Swift's extended grapheme clusters rather than on individual Unicode characters. This allows an attacker to bypass HTML entity escaping by sending a malicious string where a special HTML character (e.g., ") is part of a larger grapheme cluster (e.g., " + combining accent \u{0301}). The vulnerable function, String.htmlEscaped, would not recognize this cluster as a simple double quote and would fail to escape it, leading to a potential Cross-Site Scripting (XSS) vulnerability when the string is rendered in an HTML attribute. The provided patch confirms this analysis by replacing the grapheme-based replacement with a safer method that iterates over the string's unicodeScalars, effectively treating each part of the grapheme cluster as an individual character for escaping purposes.