Skip to content

Assertion in isWordTooShort for Thai text with useIntlWordSegmentation #9281

Description

@Jason3S

Summary

With useIntlWordSegmentation: true, checking the Thai word กระดูกสฟีนอยด์ fails with an assertion in isWordTooShort:

AssertionError [ERR_ASSERTION]: 'ดู­' == 'ดูก'
    at isWordTooShort (cspell-lib/dist/lib/textValidation/lineValidatorFactory.js:141:20)
    at splitterIsValid (cspell-lib/dist/lib/textValidation/lineValidatorFactory.js:159:17)
    at checkTextRange (cspell-lib/dist/lib/util/wordSplitter/wordSplitter.js:148:37)
    at splitIntoWords (cspell-lib/dist/lib/util/wordSplitter/wordSplitter.js:349:36)
    at split (cspell-lib/dist/lib/util/wordSplitter/wordSplitter.js:165:20)
    at _checkPossibleWords (cspell-lib/dist/lib/textValidation/lineValidatorFactory.js:320:37)

(The first string ends in a literal U+00AD soft hyphen, shown here as ­.)

In 10.3.3 and earlier the error was dropped and the file was reported as skipped (Files checked: 0, skipped: 1). Since #9267 (10.3.4) it is thrown, so the run fails.

Reproduce

cspell 10.3.4, using @cspell/dict-th-th from cspell-dicts:

cd cspell-dicts/dictionaries/th_th
printf 'กระดูกสฟีนอยด์\n' | cspell -c ./cspell-ext.json --locale=th "--languageId=*" stdin
Failed to process "stdin://" AssertionError [ERR_ASSERTION]: 'ดู­' == 'ดูก'
CSpell: Files checked: 0, skipped: 1, Issues found: 0 in 1 file with 1 error.

cspell-ext.json turns on useIntlWordSegmentation for locale: th. Any config that does the same with a Thai dictionary should reproduce it.

Cause

  1. IntlSegmentTextTransformer inserts U+00AD at each Intl.Segmenter word boundary, so the line text becomes …ดู­ก….
  2. The word splitter tries the candidate ดู­ก and removes the soft hyphen (wordSplitter.ts: word.text = word.text.replaceAll(softHyphen, '')). The text is now ดูก (3 code units), but offset still points at a 4-code-unit span in the line.
  3. isWordTooShort asserts line.text.slice(offset, offset + word.text.length) === word.text. The slice is ดู­, so the assert fails.

isWordTooShort is still the same on main. The soft hyphen changes in #9144, #9196, and #9215 likely introduced it.

Possible fixes

  • In isWordTooShort, allow for removed soft hyphens: compare against the line text with soft hyphens stripped, or skip the check when the span contains U+00AD.
  • Or have the splitter keep the original span length, so later checks can slice the line correctly after the soft hyphens are removed.

Impact

Found in cspell-dicts, where the th_th test (the first 1000 words of the Hunspell dictionary) had been skipped without error and fails after updating to 10.3.4 (streetsidesoftware/cspell-dicts#5751). Of those 1000 words, only กระดูกสฟีนอยด์ hits this. cspell-dicts excludes it from the test until this is fixed.

Activity

  1. added
    cspell-lib
    on Sep 28, 2026
  2. github-actions commented on Oct 28, 2026

    @github-actions
    Contributor

    This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  3. locked as resolved and limited conversation to collaborators on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cspell-lib

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions