Skip to content

fix: guard nighit, check_sara, check_marttra against empty input#1377

Merged
bact merged 5 commits into
PyThaiNLP:devfrom
phoneee:fix/empty-string-guards
May 1, 2026
Merged

fix: guard nighit, check_sara, check_marttra against empty input#1377
bact merged 5 commits into
PyThaiNLP:devfrom
phoneee:fix/empty-string-guards

Conversation

@phoneee
Copy link
Copy Markdown
Contributor

@phoneee phoneee commented Mar 29, 2026

What do these changes do

Fix check_sara, check_marttra, and nighit crashing on empty string or vowel-only input

Fixes #1376

  • Passed code styles and structures
  • Passed code linting checks and unit test

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.
@bact bact added the bug bugs in the library label Mar 29, 2026
@bact bact added this to PyThaiNLP Mar 29, 2026
@bact bact moved this to In progress in PyThaiNLP Mar 29, 2026
@bact bact requested a review from Copilot March 29, 2026 20:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_sara and check_marttra.
  • Make nighit raise a ValueError when w2 contains 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().

Comment thread pythainlp/morpheme/word_formation.py Outdated
Comment thread pythainlp/khavee/core.py
Comment thread pythainlp/morpheme/word_formation.py Outdated
Comment thread pythainlp/khavee/core.py
Comment thread pythainlp/khavee/core.py
Comment thread pythainlp/khavee/core.py
Comment thread pythainlp/morpheme/word_formation.py Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale label May 1, 2026
@bact
Copy link
Copy Markdown
Member

bact commented May 1, 2026

@copilot apply changes based on the comments in this thread

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@coveralls
Copy link
Copy Markdown

coveralls commented May 1, 2026

Coverage Status

Coverage is 66.643%phoneee:fix/empty-string-guards into PyThaiNLP:dev. No base build found for PyThaiNLP:dev.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 1, 2026

Comment thread pythainlp/morpheme/word_formation.py
@bact bact merged commit 5fa07a7 into PyThaiNLP:dev May 1, 2026
24 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in PyThaiNLP 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug bugs in the library stale

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

4 participants