انتقل إلى المحتوى الرئيسي

Function: displayNameScriptProblem()

displayNameScriptProblem(name, scripts): DisplayNameScriptProblem | undefined

Defined in: packages/contracts/src/display-name.ts:244

The script rule: every character of the name that has a script belongs to one on the deployment's allowlist, and no single word mixes two of them.

The allowlist half looks at the whole name. Characters of script Common (digits, punctuation, symbols, spaces) and Inherited (combining marks) belong to no script and are set aside; every other code point must match an allowed script. The rule is on the script of each code point (Script, not Script_Extensions), so the answer for a character does not depend on its neighbours. A code point with no script at all (unassigned, private use) is in no allowlist and is refused.

The mixing half looks at one word at a time, and a word is a maximal run of letters and combining marks (WORD): \p{L}, \p{M}, and the zero-width non-joiner and joiner. Anything else ends the word: a space, a hyphen, a slash, a digit, an apostrophe, any punctuation. So Al-بنك, بنك-ABC and Abd/عبد are each two words of one script and pass, which a bilingual Arabic and English platform needs: a Latin brand joined to an Arabic word by a hyphen is a real organisation name. Okto1D is two Latin words and passes. OktoІD with a Cyrillic І is one word and fails either way, as a script that is not allowed, or as a mixed word where Cyrillic is allowed.

What joins letters inside one Arabic word stays inside the word. The tatweel (U+0640) is a letter by general category, so \p{L} already holds it, although its script is Common. The zero-width non-joiner and joiner (U+200C, U+200D) are format characters that Persian and Arabic spelling put between the letters of a single word, and the display-name pattern allows them for that reason; they are named in the word class so that one cannot be used to cut a mixed word into two clean halves that render as one.

The argument against this definition: a hyphen or a slash can now join two scripts in what a reader sees as one token, where a word used to be everything between spaces. It is accepted because the allowlist, not the word rule, is what keeps lookalike scripts out, and the two scripts allowed by default, Latin and Arabic, do not resemble each other. A deployment that allowlists Latin beside Cyrillic or Greek should know what it then lets through: a word written wholly in Cyrillic letters that look Latin, joined by a hyphen to a Latin word, passes. That is the case the module header says needs a confusables table.

It still costs something on purpose: a name in a third script is refused until the operator widens the allowlist.

Parameters​

name​

string

A display name.

scripts​

DisplayNameScripts

The deployment's compiled allowlist.

Returns​

DisplayNameScriptProblem | undefined

script-not-allowed when any character fails the allowlist, checked first over the whole name; otherwise mixed-script-word when a word mixes two allowed scripts; otherwise undefined.