Patchwork [4,of,7] bundle2: urlquote stream parameter name and value

login
register
mail settings
Submitter Pierre-Yves David
Date March 21, 2014, 9:57 p.m.
Message ID <61c50b7ad004815e93d6.1395439049@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4027/
State Accepted
Commit 9785c3f8f59865df934550e667a486ef79e8eb15
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 1395189491 25200
#      Tue Mar 18 17:38:11 2014 -0700
# Node ID 61c50b7ad004815e93d6d3c75446fe5b7f520786
# Parent  eb7c292fe0ad0d7b03d1776955f3c51762b90bb4
bundle2: urlquote stream parameter name and value

This introduces support for arbitrary characters in stream parameters name and
value.  The urlquote format has been chosen because it is:

- simple,
- standard,
- no-op on simple alphanumerical entry.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -41,13 +41,11 @@  Binary format is as follow
 
   A blob of `params size` containing the serialized version of all stream level
   parameters.
 
   The blob contains a space separated list of parameters. parameter with value
-  are stored in the form `<name>=<value>`.
-
-  Special character in param name are not supported yet.
+  are stored in the form `<name>=<value>`. Both name and value are urlquoted.
 
   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.
@@ -70,10 +68,11 @@  Binary format is as follow
   Currently forced to 0 in the current state of the implementation
 """
 
 import util
 import struct
+import urllib
 
 import changegroup
 from i18n import _
 
 _pack = struct.pack
@@ -114,12 +113,13 @@  class bundle20(object):
 
     def _paramchunk(self):
         """return a encoded version of all stream parameters"""
         blocks = []
         for par, value in self._params:
-            # XXX no escaping yet
+            par = urllib.quote(par)
             if value is not None:
+                value = urllib.quote(value)
                 par = '%s=%s' % (par, value)
             blocks.append(par)
         return ' '.join(blocks)
 
 class unbundle20(object):
diff --git a/tests/test-bundle2.t b/tests/test-bundle2.t
--- a/tests/test-bundle2.t
+++ b/tests/test-bundle2.t
@@ -130,5 +130,13 @@  Test unbundling
   - caution
   - elephants
   - meal
       vegan
   parts count:   0
+
+parameter with special char in value
+---------------------------------------------------
+
+Test generation
+
+  $ hg bundle2 --param 'e|! 7/=babar%#==tutu' --param simple
+  HG20\x00)e%7C%21%207/=babar%25%23%3D%3Dtutu simple\x00\x00 (no-eol) (esc)