PyThaiNLP / PyThaiNLP/pythainlp

bug: check_sara, check_marttra, nighit crash on empty or vowel-only input

Open
#1,376 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
1.2k
Forks
304
Avg merge
2d 14h
Merged PRs (30d)
14

Description

Description

Three public functions crash with IndexError when given empty strings or inputs lacking expected characters:

  1. KhaveeVerifier.check_sara("")IndexError at line 58 — word[-1] on empty string
  2. KhaveeVerifier.check_marttra("")IndexError at line 257 — word[-1] on empty string
  3. nighit("สํ", "าี")IndexError at line 41 — [...][0] on empty list when w2 has no Thai consonants
Expected results
kv.check_sara("")       # → "" or raise ValueError
kv.check_marttra("")    # → "" or raise ValueError
nighit("สํ", "าี")     # → raise ValueError
Current results
kv.check_sara("")       # IndexError: string index out of range
kv.check_marttra("")    # IndexError: string index out of range
nighit("สํ", "าี")     # IndexError: list index out of range
Steps to reproduce
from pythainlp.khavee import KhaveeVerifier
kv = KhaveeVerifier()
kv.check_sara("")        # crash
kv.check_marttra("")     # crash

from pythainlp.morpheme import nighit
nighit("สํ", "าี")      # crash
PyThaiNLP version

5.3.3

Python version

3.13

Operating system and version

macOS

Possible solution
  • check_sara/check_marttra: Add if not word: return "" at function start.
  • nighit: Check consonant list non-empty before [0], raise ValueError with descriptive message.
Files
  • pythainlp/khavee/core.py (lines 58, 257)
  • pythainlp/morpheme/word_formation.py (line 41)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with pythainlp/khavee/core.py at check_sara and check_marttra, then inspect pythainlp/morpheme/word_formation.py at nighit. Reproduce the empty and vowel-only inputs from the issue and find the existing tests for these functions. Add regression coverage and ensure the functions no longer produce IndexError, using the intended empty-result or ValueError behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.