Patchwork [6,of,7] bundle2: refuse empty parameter name

login
register
mail settings
Submitter Pierre-Yves David
Date March 21, 2014, 9:57 p.m.
Message ID <ca51ee1121790c891e1f.1395439051@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4029/
State Accepted
Commit 8c74b3ce5b7059d8acdfd24175e29f77730457df
Headers show

Comments

Pierre-Yves David - March 21, 2014, 9:57 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1395193231 25200
#      Tue Mar 18 18:40:31 2014 -0700
# Node ID ca51ee1121790c891e1f98cd18d8b664f131ea31
# Parent  7d3033759ef21b18f4c85a2bca2de2c54c77e42d
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.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -43,20 +43,21 @@  Binary format is as follow
   parameters.
 
   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
     crazy usage.
   - Textual data allow easy human inspection of a the bundle2 header in case of
     troubles.
 
   Any Applicative level options MUST go into a bundle2 part instead.
 
-
 Payload part
 ------------------------
 
 Binary format is as follow
 
@@ -95,10 +96,12 @@  class bundle20(object):
         self._params = []
         self._parts = []
 
     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):
         yield _magicstring
         param = self._paramchunk()
diff --git a/tests/test-bundle2.t b/tests/test-bundle2.t
--- a/tests/test-bundle2.t
+++ b/tests/test-bundle2.t
@@ -8,10 +8,11 @@  Create an extension to test bundle2 API
   > code. We still need to be able to test it while it grow up.
   > """
   > 
   > import sys
   > from mercurial import cmdutil
+  > from mercurial import util
   > from mercurial import bundle2
   > cmdtable = {}
   > command = cmdutil.command(cmdtable)
   > 
   > @command('bundle2',
@@ -20,11 +21,14 @@  Create an extension to test bundle2 API
   > def cmdbundle2(ui, repo, **opts):
   >     """write a bundle2 container on standard ouput"""
   >     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)
   > 
   > @command('unbundle2', [], '')
@@ -147,5 +151,14 @@  Test unbundling
   options count: 2
   - e|! 7/
       babar%#==tutu
   - simple
   parts count:   0
+
+Test buggy input
+---------------------------------------------------
+
+empty parameter name
+
+  $ hg bundle2 --param '' --quiet
+  abort: empty parameter name
+  [255]