Cotton code
15 lines · 1.2 KB · TypeScriptRaw
/** * Whether `word` stands in `text` the way a word kept in the clear does (BLIND SEARCH STEADY, 25 Nov 2026): not * straight after a base64url character. Everything an object keeps of a sealed row is base64url (bodies, wrapped * keys, blind tokens), and its ids and times are hex and digits, so a bare substring check over a dump of it finds a * short word by chance: "ref-1" in about one run of 1,400 of blind-search, a four-digit number far more often in hex. * A word kept in the clear sits in a string after a quote, a space or a mark, or straight after a seal's prefix * ("s1:"), and is found here wherever it stands so. Case is as given: lowercase the text first to ask without it. */export function holdsWord(text: string, word: string): boolean {  // A word with a character base64url never holds (a space, "/", "@", ":", ".") cannot arise inside a sealed run by  // chance: it is looked for as it is, anywhere, so a phrase or a path is no less caught than before.  if (!/^[A-Za-z0-9_-]+$/.test(word)) return text.includes(word);  const escaped = word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");  return new RegExp(`(?<![A-Za-z0-9_-])${escaped}`, "u").test(text);}