Description
Three public functions crash with IndexError when given empty strings or inputs lacking expected characters:
KhaveeVerifier.check_sara("") → IndexError at line 58 — word[-1] on empty string
KhaveeVerifier.check_marttra("") → IndexError at line 257 — word[-1] on empty string
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)
Description
Three public functions crash with
IndexErrorwhen 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 consonantsExpected results
Current results
Steps to reproduce
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)