changeset 20813:8c74b3ce5b70

bundle2: refuse empty parameter name The bundle2 now raise value error when seeing invalid parameter names. The first introduced rules is: no empty parameter. The test extension is improve to properly abort when ValueError are encountered.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 18 Mar 2014 18:40:31 -0700
parents e2f908773754
children 8532f5e1b9df
files mercurial/bundle2.py tests/test-bundle2.t
diffstat 2 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundle2.py	Tue Mar 18 17:43:08 2014 -0700
+++ b/mercurial/bundle2.py	Tue Mar 18 18:40:31 2014 -0700
@@ -45,6 +45,8 @@
   The blob contains a space separated list of parameters. parameter with value
   are stored in the form `<name>=<value>`. Both name and value are urlquoted.
 
+  Empty name are obviously forbidden.
+
   Stream parameters use a simple textual format for two main reasons:
 
   - Stream level parameters should remains simple and we want to discourage any
@@ -54,7 +56,6 @@
 
   Any Applicative level options MUST go into a bundle2 part instead.
 
-
 Payload part
 ------------------------
 
@@ -97,6 +98,8 @@
 
     def addparam(self, name, value=None):
         """add a stream level parameter"""
+        if not name:
+            raise ValueError('empty parameter name')
         self._params.append((name, value))
 
     def getchunks(self):
--- a/tests/test-bundle2.t	Tue Mar 18 17:43:08 2014 -0700
+++ b/tests/test-bundle2.t	Tue Mar 18 18:40:31 2014 -0700
@@ -10,6 +10,7 @@
   > 
   > import sys
   > from mercurial import cmdutil
+  > from mercurial import util
   > from mercurial import bundle2
   > cmdtable = {}
   > command = cmdutil.command(cmdtable)
@@ -22,7 +23,10 @@
   >     bundler = bundle2.bundle20()
   >     for p in opts['param']:
   >         p = p.split('=', 1)
-  >         bundler.addparam(*p)
+  >         try:
+  >             bundler.addparam(*p)
+  >         except ValueError, exc:
+  >             raise util.Abort('%s' % exc)
   > 
   >     for chunk in bundler.getchunks():
   >         ui.write(chunk)
@@ -149,3 +153,12 @@
       babar%#==tutu
   - simple
   parts count:   0
+
+Test buggy input
+---------------------------------------------------
+
+empty parameter name
+
+  $ hg bundle2 --param '' --quiet
+  abort: empty parameter name
+  [255]