-
-
Notifications
You must be signed in to change notification settings - Fork 294
fix: guard nighit, check_sara, check_marttra against empty input #1377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -54,6 +54,9 @@ def check_sara(self, word: str) -> str: | |||||||||||
| sara = [] | ||||||||||||
| countoa = 0 | ||||||||||||
|
|
||||||||||||
| if not word: | ||||||||||||
| return "" | ||||||||||||
|
||||||||||||
| return "" | |
| return "Can't find Sara in this word" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error/warning message should go to standard error/warning raises, not the return value.
Copilot
AI
Mar 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After stripping a trailing karun (word = word[:-2]), word can become empty (e.g. input like "ก์"). The function later indexes word[-1] (e.g. in the ออ handling), which will still raise IndexError. Consider re-checking if not word immediately after the karun-strip (and returning an appropriate value) to fully guard against empty-after-normalization cases.
| word = word[:-2] | |
| word = word[:-2] | |
| # After removing the karun, the word may become empty (e.g. "ก์") | |
| if not word: | |
| return "" |
Copilot
AI
Mar 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning an empty string for empty input is inconsistent with the existing error signaling in this API (e.g. returning "Can't find Marttra in this word" for unclassified words). Consider returning the same "Can't find…" string or raising a ValueError to avoid an ambiguous "" result.
| return "" | |
| return "Can't find Marttra in this word" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error/warning message should go to standard error/warning raises, not the return value.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,12 @@ def nighit(w1: str, w2: str) -> str: | |
| newword = [] | ||
| newword.append(list_w1[0]) | ||
| newword.append("ั") | ||
| consonant_start = [i for i in list_w2 if i in set(thai_consonants)][0] | ||
| consonants_in_w2 = [i for i in list_w2 if i in set(thai_consonants)] | ||
|
||
| if not consonants_in_w2: | ||
| raise ValueError( | ||
| f"w2 {w2!r} contains no Thai consonants." | ||
| ) | ||
| consonant_start = consonants_in_w2[0] | ||
|
Comment on lines
+41
to
+46
|
||
| if consonant_start in ["ก", "ช", "ค", "ข", "ง"]: | ||
| newword.append("ง") | ||
| elif consonant_start in ["จ", "ฉ", "ช", "ฌ"]: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These new empty-input behaviors (returning "" for check_sara/check_marttra) are not covered by existing khavee tests. Add unit tests that exercise empty-string input to prevent regressions back to IndexError.