Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pythainlp/corpus/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,10 +632,10 @@ def _check_version(cause: str) -> bool:
check = _version2int(temp_parts[0]) < v < _version2int(temp_parts[1])
elif cause.startswith("<="):
temp = cause.replace("<=", "")
check = v <= _version2int(temp[0])
check = v <= _version2int(temp)
elif cause.startswith("<"):
temp = cause.replace("<", "")
check = v < _version2int(temp[0])
check = v < _version2int(temp)

return check

Expand Down
16 changes: 16 additions & 0 deletions tests/core/test_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
tnc,
ttc,
)
from pythainlp.corpus.core import _check_version, _version2int
from pythainlp.corpus.util import revise_newmm_default_wordset


Expand Down Expand Up @@ -621,3 +622,18 @@ def test_thai_synonyms_loads_valid_rows(self):
self.assertEqual(
result["synonym"], [["cat", "kitty"], ["dog"]]
)

def test_check_version(self):
# Reproduce: _check_version with <= and < used temp[0] which
# only gets the first character of the version string instead
# of the full version, causing incorrect comparisons.
self.assertTrue(_check_version("*"))
self.assertTrue(_check_version("<=9999.9.9"))
self.assertTrue(_check_version("<9999.9.9"))
self.assertTrue(_check_version(">=0.0.1"))
self.assertTrue(_check_version(">0.0.1"))
self.assertFalse(_check_version("<=0.0.1"))
self.assertFalse(_check_version("<0.0.1"))
# version2int consistency
self.assertNotEqual(_version2int("5.3.3"), _version2int("5"))
self.assertEqual(_version2int("2.0"), _version2int("2.0.0"))
Loading