Exercise 2: Why This Pipeline Can't Split a Surrogate Pair — Possible Solution ==================================================================== WHAT path.join('/') ACTUALLY DOES ------------------------------ params.path arrives as an array, already split into whole URL segments by Next.js's own router - each array element is one complete path segment, e.g. ['programming', '水']. join('/') concatenates these whole elements with a separator between them; it never looks inside any single element to inspect or modify individual characters or code units. Even if one element is a rare astral-plane character needing a surrogate pair, join() treats that entire element as one indivisible unit and copies it into the result unchanged. WHAT prisma.page.findUnique({ where: { fullPath } }) ACTUALLY DOES ------------------------------ This is an equality comparison, not a substring or range operation. Prisma passes the whole fullPath string to the database as a single bound parameter, and the database compares it byte-for-byte (at the storage/collation level) against the stored column value. Neither Prisma nor the database ever reads "the first N code units" or "code units 3 through 7" of the string - the entire value is either equal to a stored row or it isn't. WHY NEITHER OPERATION CAN TRIGGER THE RISK ------------------------------ The surrogate-pair corruption risk this chapter describes only happens when code slices a string AT A SPECIFIC OFFSET that happens to fall between the two halves of a surrogate pair. Both join() (which never slices within an element) and an equality comparison (which never slices at all) are structurally incapable of choosing an offset in the first place - there's no operation anywhere in this path that could land "in the middle" of any character, common or rare. WHY THIS WORKS AS AN ANSWER ------------------------------ It explains the mechanism, not just the conclusion - identifying that the risk specifically requires an offset-based slice operation, and that neither function used in this pipeline performs one, rather than just asserting "these are safe" without explaining what makes them safe.