extensions: prevent a crash on py3 when testing a bad extension minimum
authorMatt Harbison <matt_harbison@yahoo.com>
Mon, 20 Sep 2021 14:16:10 -0400
changeset 48015 a9bedc56f025
parent 48014 0dc4cc654d96
child 48016 5caec48d9a01
extensions: prevent a crash on py3 when testing a bad extension minimum A `None` placeholder is populated for each missing component by `util.versiontuple()`, which could safely be used with `>` on py2, but not py3. I guess there's another hole here where if the string is entirely bogus (i.e no numbers), it will be treated as 0.0, and always load. But that's always been the case. Differential Revision: https://phab.mercurial-scm.org/D11475
mercurial/extensions.py
tests/test-extension.t
--- a/mercurial/extensions.py	Mon Sep 20 11:22:27 2021 -0400
+++ b/mercurial/extensions.py	Mon Sep 20 14:16:10 2021 -0400
@@ -224,8 +224,12 @@
     minver = getattr(mod, 'minimumhgversion', None)
     if minver:
         curver = util.versiontuple(n=2)
+        extmin = util.versiontuple(minver, 2)
 
-        if None in curver or util.versiontuple(minver, 2) > curver:
+        if None in extmin:
+            extmin = (extmin[0] or 0, extmin[1] or 0)
+
+        if None in curver or extmin > curver:
             msg = _(
                 b'(third party extension %s requires version %s or newer '
                 b'of Mercurial (current: %s); disabling)\n'
--- a/tests/test-extension.t	Mon Sep 20 11:22:27 2021 -0400
+++ b/tests/test-extension.t	Mon Sep 20 14:16:10 2021 -0400
@@ -1692,6 +1692,25 @@
   $ hg --config extensions.minversion=minversion3.py version 2>&1 | egrep '\(third'
   [1]
 
+Don't explode on py3 with a bad version number
+
+  $ cat > minversion4.py << EOF
+  > from mercurial import util
+  > util.version = lambda: b'3.5'
+  > minimumhgversion = b'3'
+  > EOF
+  $ hg --config extensions.minversion=minversion4.py version -v
+  Mercurial Distributed SCM (version 3.5)
+  (see https://mercurial-scm.org for more information)
+  
+  Copyright (C) 2005-* Olivia Mackall and others (glob)
+  This is free software; see the source for copying conditions. There is NO
+  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  
+  Enabled extensions:
+  
+    minversion  external  
+
 Restore HGRCPATH
 
   $ HGRCPATH=$ORGHGRCPATH