Skip to content

Commit 9dfae5a

Browse files
authored
Merge pull request #1379 from phoneee/fix/check-version-string-slice
fix: use full version string in _check_version for <= and < operators
2 parents acc9360 + 2287acf commit 9dfae5a

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

pythainlp/corpus/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,10 +632,10 @@ def _check_version(cause: str) -> bool:
632632
check = _version2int(temp_parts[0]) < v < _version2int(temp_parts[1])
633633
elif cause.startswith("<="):
634634
temp = cause.replace("<=", "")
635-
check = v <= _version2int(temp[0])
635+
check = v <= _version2int(temp)
636636
elif cause.startswith("<"):
637637
temp = cause.replace("<", "")
638-
check = v < _version2int(temp[0])
638+
check = v < _version2int(temp)
639639

640640
return check
641641

tests/core/test_corpus.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
tnc,
3232
ttc,
3333
)
34+
from pythainlp.corpus.core import _check_version, _version2int
3435
from pythainlp.corpus.util import revise_newmm_default_wordset
3536

3637

@@ -621,3 +622,18 @@ def test_thai_synonyms_loads_valid_rows(self):
621622
self.assertEqual(
622623
result["synonym"], [["cat", "kitty"], ["dog"]]
623624
)
625+
626+
def test_check_version(self):
627+
# Reproduce: _check_version with <= and < used temp[0] which
628+
# only gets the first character of the version string instead
629+
# of the full version, causing incorrect comparisons.
630+
self.assertTrue(_check_version("*"))
631+
self.assertTrue(_check_version("<=9999.9.9"))
632+
self.assertTrue(_check_version("<9999.9.9"))
633+
self.assertTrue(_check_version(">=0.0.1"))
634+
self.assertTrue(_check_version(">0.0.1"))
635+
self.assertFalse(_check_version("<=0.0.1"))
636+
self.assertFalse(_check_version("<0.0.1"))
637+
# version2int consistency
638+
self.assertNotEqual(_version2int("5.3.3"), _version2int("5"))
639+
self.assertEqual(_version2int("2.0"), _version2int("2.0.0"))

0 commit comments

Comments
 (0)