One Word, Two Strings: ZWJ, Conjuncts, and Why Sinhala Text Breaks When You Copy It
Published October 2026 · Reviewed 9 November 2026 · Estwoco Team
Here is a bug report we have effectively received more than once, in different words: "I searched my document for this word and it says there are no matches, but I can see the word right there on the page." The text is Sinhala. It looks correct. It is not the same string.
This is not a Sinhala-specific mystery, but Sinhala is a particularly good place to see it, because a single visual syllable in Sinhala can be built from several Unicode code points, and some of those code points are invisible. When an invisible character is in the wrong place, nothing looks broken and everything stops matching. This article walks through what is actually in the string, where the zero-width joiner goes, and why the usual fix for text mismatches — normalisation — does nothing here.
How Sinhala is encoded, briefly
Sinhala occupies its own contiguous block in Unicode, from U+0D80 to U+0DFF, added in Unicode 3.0. Inside that block are three kinds of characters you need to keep apart:
- Consonants, each a full character with its own code point — for example ක (U+0D9A).
- Dependent vowel signs (pili), which attach to the preceding consonant and cannot stand alone — for example ා (U+0DCF), the vowel sign that turns "ka" into "kaa".
- U+0DCA, the al-lakuna — the "hal kirima" sign that cancels the inherent vowel of a consonant. This one character is responsible for most of the complexity that follows.
The important consequence is that a Sinhala syllable which looks like one unit on screen is, at the data level, a short sequence. The renderer draws the sequence as a single visual cluster; the string stores the pieces separately. Everything that compares strings — search, sort, deduplication, form validation, word counting — sees the pieces, not the picture.
The sequences, spelled out
Take the consonant ක and build on it:
| What you see | Code points | What each part does |
|---|---|---|
| ක | U+0D9A | The consonant alone. It carries an inherent vowel sound. |
| කා | U+0D9A U+0DCF | Consonant plus the vowel sign that lengthens the vowel. |
| ක් | U+0D9A U+0DCA | Consonant plus al-lakuna: the vowel is cancelled, leaving a bare consonant. |
| ක්ර | U+0D9A U+0DCA U+200D U+0DBB | Consonant, al-lakuna, zero-width joiner, then ර. The ZWJ requests the joined form rather than a full separate consonant. |
| ක්ය | U+0D9A U+0DCA U+200D U+0DBA | Same pattern with ය, again producing the joined form. |
The last two rows are where trouble starts. U+200D is the zero-width joiner, usually written ZWJ. It has no visible shape of its own. It tells the text renderer: treat the characters on either side as a single joined unit. In Sinhala that is how the yansaya and rakaransaya forms are requested, and how certain conjuncts are built.
Remove the ZWJ and you get a different string — consonant, al-lakuna, consonant — which many fonts will render differently, with the second consonant shown in full rather than joined. But in some fonts, at small sizes, and especially on low-resolution screens, the two renderings are close enough that a reader cannot tell which one they are looking at. That is the trap: the text is visually ambiguous and semantically unambiguous. The computer is right; your eyes are being reasonable but not precise.
Why this breaks things you would not expect
Because the mismatch is invisible, it surfaces as a series of unrelated-looking problems:
- Search fails. A find-in-page or database lookup for the joined form does not match a document stored with the unjoined form.
- Duplicates appear. Two records that a human would call the same word become two distinct keys, so deduplication and grouping quietly fail.
- Sorting misbehaves. Ordering compares code point by code point, so a stray joiner can push a word into a different position than expected.
- Form validation rejects valid input. Length limits, pattern checks, and username rules count invisible characters as well as visible ones.
- Copy-paste between applications changes the text. Some editors and input fields strip or insert joiners, so a word can be correct in one application and subtly altered after a paste into another.
- Accessibility output gets noisy. Screen readers can announce a hal kirima where a reader would expect silence, or split a syllable that should be spoken as one unit.
Why normalisation does not save you
The standard answer to "two strings that should be equal are not equal" is Unicode normalisation. Latin text has both composed and decomposed forms, so applying NFC collapses them into one representation and comparison works. It is a reasonable instinct, and for Sinhala it does not help.
Sinhala's letters and vowel signs do not have canonical decomposition mappings. There is no equivalent of "e with an accent" that splits into "e" plus a combining accent. The characters are already atomic. That means NFC and NFD leave a Sinhala string essentially as they found it: if the ZWJ is missing, normalisation will not add it, and if it is present, normalisation will not remove it.
So the mismatch is not a normalisation problem, it is an authoring problem. The two strings are genuinely different, both are valid Unicode, and no general-purpose cleanup step can decide which one the author meant. The fix has to happen when the text is produced.
What a converter has to guarantee
This is the constraint that shaped Sinhalata. If you are converting phonetic typing into Sinhala, you are not just choosing letters — you are choosing one sequence among several that may look the same. The converter therefore has to make the same choice every time, for the same input.
Three rules do most of the work:
- One canonical output per syllable. For a given combination of consonant, vowel sign, and joined form, emit exactly one predetermined sequence. Never let two code paths produce two different spellings of the same visible syllable.
- Place the joiner deliberately, not incidentally. The ZWJ goes between the al-lakuna and the consonant it joins, and it is inserted by the conversion rule that recognises the joined form — not by a general "insert a joiner here" pass that might also fire where it is not wanted.
- Compare at the sequence level, not the display level. When the converter checks whether a syllable is already correct, it compares the stored sequence it intends to emit, not the rendered appearance.
The alternative — emitting whatever the font happens to accept — produces documents that look right on the machine that typed them and fail quietly everywhere else. That is the same failure mode as the legacy font era, just one layer deeper: the text is real Unicode, but it is inconsistently encoded Unicode.
How to check your own Sinhala text
If you suspect you are dealing with this, a few practical checks:
- Count characters, not shapes. Paste the word into a plain-text editor or a browser console and ask for the length. A syllable you read as three shapes may be four or five code points.
- Look for invisible characters. In a code editor, enable rendering of control and invisible characters; the joiner will appear where a space-like marker is. Searching for
\u200Dor\u200Cwith a regular expression is usually faster. - Test whether the two versions differ. Put both spellings in a script and compare them directly. If they are unequal, the difference is in the invisible characters, because the visible ones are the same.
- Do not repair with normalisation. Running NFC or NFD will not restore a missing joiner and can cost you the ability to see what actually changed.
- Retext with a converter that is consistent. The reliable fix is to regenerate the text from a tool that emits one canonical form, rather than patching it by hand.
If you are building software that accepts Sinhala input, the same logic applies in reverse: define the canonical sequence you store, reject or rewrite the alternatives on input, and do your comparisons on that canonical form rather than on what a font renders.
The wider point
Unicode support is not a binary property that a language either has or lacks. It is a set of decisions about how sequences get produced and maintained. Sinhala has had a proper place in Unicode for a long time, and text that is technically valid Unicode can still be unusable for search and matching if it was authored inconsistently. The interesting work in Sinhala computing has moved on from "can we represent this at all" to "can we agree on exactly one representation — and produce it every time".
Sinhalata emits a single, consistent Unicode sequence for each syllable, so the text you produce matches the text you search for later.