Patchwork D7969: exchange: check the `ui.clonebundleprefers` form while processing (issue6257)

login
register
mail settings
Submitter phabricator
Date Feb. 7, 2020, 2:59 p.m.
Message ID <04dd007ea8cfe9e00bb77565a1e687c2@localhost.localdomain>
Download mbox | patch
Permalink /patch/45019/
State Not Applicable
Headers show

Comments

phabricator - Feb. 7, 2020, 2:59 p.m.
mharbison72 updated this revision to Diff 19984.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7969?vs=19517&id=19984

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7969/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7969

AFFECTED FILES
  mercurial/exchange.py
  tests/test-clonebundles.t

CHANGE DETAILS




To: mharbison72, #hg-reviewers, marmoute
Cc: marmoute, mercurial-devel

Patch

diff --git a/tests/test-clonebundles.t b/tests/test-clonebundles.t
--- a/tests/test-clonebundles.t
+++ b/tests/test-clonebundles.t
@@ -455,6 +455,19 @@ 
   no changes found
   2 local changesets published
 
+Test a bad attribute list
+
+  $ hg --config ui.clonebundleprefers=bad clone -U http://localhost:$HGPORT bad-input
+  abort: invalid ui.clonebundleprefers item: bad
+  (each comma separated item should be key=value pairs)
+  [255]
+  $ hg --config ui.clonebundleprefers=key=val,bad,key2=val2 clone \
+  >    -U http://localhost:$HGPORT bad-input
+  abort: invalid ui.clonebundleprefers item: bad
+  (each comma separated item should be key=value pairs)
+  [255]
+
+
 Test interaction between clone bundles and --stream
 
 A manifest with just a gzip bundle
diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -3068,7 +3068,15 @@ 
     if not prefers:
         return list(entries)
 
-    prefers = [p.split(b'=', 1) for p in prefers]
+    def _split(p):
+        if b'=' not in p:
+            hint = _(b"each comma separated item should be key=value pairs")
+            raise error.Abort(
+                _(b"invalid ui.clonebundleprefers item: %s") % p, hint=hint
+            )
+        return p.split(b'=', 1)
+
+    prefers = [_split(p) for p in prefers]
 
     items = sorted(clonebundleentry(v, prefers) for v in entries)
     return [i.value for i in items]