fix: guard nighit, check_sara, check_marttra against empty input#1377
Merged
Conversation
nighit() crashed with IndexError when w2 had no consonants.
check_sara("") and check_marttra("") crashed accessing word[-1].
Add input validation with clear error messages.
Contributor
There was a problem hiding this comment.
Pull request overview
Guards three Thai-language public helpers (KhaveeVerifier.check_sara, KhaveeVerifier.check_marttra, and morpheme.nighit) against previously crashing edge-cases (empty input / no-consonant input), addressing issue #1376.
Changes:
- Add early empty-input returns to
check_saraandcheck_marttra. - Make
nighitraise aValueErrorwhenw2contains no Thai consonants (instead of crashing).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
pythainlp/morpheme/word_formation.py |
Adds a safe guard for nighit() when w2 has no Thai consonants. |
pythainlp/khavee/core.py |
Adds empty-input guards to avoid IndexError in check_sara() and check_marttra(). |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
|
This PR is stale because it has been open for 30 days with no activity. |
Member
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Added type checks and string handling for inputs.
|
2 tasks
bact
reviewed
May 1, 2026
bact
approved these changes
May 1, 2026
bact
added a commit
that referenced
this pull request
May 1, 2026
PR #1377 adds guardrails to nighit(). This PR add tests to those guardrails. Signed-off-by: Arthit Suriyawongkul <arthit@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What do these changes do
Fix
check_sara,check_marttra, andnighitcrashing on empty string or vowel-only inputFixes #1376