PyThaiNLP / PyThaiNLP/pythainlp
bug: check_sara, check_marttra, nighit crash on empty or vowel-only input
Open
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:
KhaveeVerifier.check_sara("")→IndexErrorat line 58 —word[-1]on empty stringKhaveeVerifier.check_marttra("")→IndexErrorat line 257 —word[-1]on empty stringnighit("สํ", "าี")→IndexErrorat 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: Addif not word: return ""at function start.nighit: Check consonant list non-empty before[0], raiseValueErrorwith descriptive message.
Files
pythainlp/khavee/core.py(lines 58, 257)pythainlp/morpheme/word_formation.py(line 41)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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