[PATCH] scheme: don't crash on invalid URLs

Mads Kiilerich mads at kiilerich.com
Thu Apr 11 15:35:11 CDT 2013


# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1365684082 -7200
#      Thu Apr 11 14:41:22 2013 +0200
# Node ID 6f4c6dc72f0f7cb83e268741c98a61aefbb7e0f4
# Parent  50c464441c03d2c568d8ead7ab4f8a3a7c512d2f
scheme: don't crash on invalid URLs

diff --git a/hgext/schemes.py b/hgext/schemes.py
--- a/hgext/schemes.py
+++ b/hgext/schemes.py
@@ -62,7 +62,10 @@
 
     def instance(self, ui, url, create):
         # Should this use the util.url class, or is manual parsing better?
-        url = url.split('://', 1)[1]
+        try:
+            url = url.split('://', 1)[1]
+        except IndexError:
+            raise util.Abort(_("no '://' in scheme url '%s'") % url)
         parts = url.split('/', self.parts)
         if len(parts) > self.parts:
             tail = parts[-1]
diff --git a/tests/test-schemes.t b/tests/test-schemes.t
--- a/tests/test-schemes.t
+++ b/tests/test-schemes.t
@@ -14,6 +14,15 @@
   $ echo a > a
   $ hg ci -Am initial
   adding a
+
+invalid scheme
+
+  $ hg log -R z:z
+  abort: no '://' in scheme url 'z:z'
+  [255]
+
+http scheme
+
   $ hg serve -n test -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log
   $ cat hg.pid >> $DAEMON_PIDS
   $ hg incoming l://


More information about the Mercurial-devel mailing list