From d0bc383a79fd77f1f4a402dde0a2566329b09716 Mon Sep 17 00:00:00 2001 From: Job Evers-Meltzer Date: Mon, 25 Jul 2016 12:25:10 -0500 Subject: [PATCH] bug fix: version comparison is not lexographic. Use distutils.version to compare version strings. --- lbrynet/lbrynet_daemon/LBRYDaemon.py | 3 ++- tests/lbrynet/lbrynet_daemon/test_LBRYDaemon.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lbrynet/lbrynet_daemon/LBRYDaemon.py b/lbrynet/lbrynet_daemon/LBRYDaemon.py index fceacec15..bf5cfd317 100644 --- a/lbrynet/lbrynet_daemon/LBRYDaemon.py +++ b/lbrynet/lbrynet_daemon/LBRYDaemon.py @@ -1,6 +1,7 @@ import binascii from datetime import datetime from decimal import Decimal +import distutils.version import locale import logging.handlers import mimetypes @@ -2314,4 +2315,4 @@ def get_version_from_tag(tag): def compare_versions(a, b): """Returns True if version a is more recent than version b""" - return a > b + return distutils.version.StrictVersion(a) > distutils.version.StrictVersion(b) diff --git a/tests/lbrynet/lbrynet_daemon/test_LBRYDaemon.py b/tests/lbrynet/lbrynet_daemon/test_LBRYDaemon.py index 104e06c01..a0d1c346f 100644 --- a/tests/lbrynet/lbrynet_daemon/test_LBRYDaemon.py +++ b/tests/lbrynet/lbrynet_daemon/test_LBRYDaemon.py @@ -36,3 +36,6 @@ class MiscTests(unittest.TestCase): def test_error_is_thrown_when_version_cant_be_parsed(self): with self.assertRaises(Exception): LBRYDaemon.get_version_from_tag('garbage') + + def test_compare_versions_isnot_lexographic(self): + self.assertTrue(LBRYDaemon.compare_versions('0.3.10', '0.3.6'))