# HG changeset patch # User Gregory Szorc # Date 2016-08-06 20:55:21 # Node ID 62e2e048d068cc2da6bb63d619126708f8cb3967 # Parent bb04f96df51c2d2523839edba1f2d51ba9e6f43d wireproto: unescape argument names in batch command (BC) Clients escape both argument names and values when using the batch command. Yet the server was only unescaping argument values. Fortunately we don't have any argument names that need escaped. But that isn't an excuse to lack symmetry in the code. Since the server wasn't properly unescaping argument names, this means we can never introduce an argument to a batchable command that needs escaped because an old server wouldn't properly decode its name. So we've introduced an assertion to detect the accidental introduction of this in the future. Of course, we could introduce a server capability that says the server knows how to decode argument names and allow special argument names to go through. But until there is a need for it (which I doubt there will be), we shouldn't bother with adding an unused capability. diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py --- a/mercurial/wireproto.py +++ b/mercurial/wireproto.py @@ -191,6 +191,11 @@ def encodebatchcmds(req): """Return a ``cmds`` argument value for the ``batch`` command.""" cmds = [] for op, argsdict in req: + # Old servers didn't properly unescape argument names. So prevent + # the sending of argument names that may not be decoded properly by + # servers. + assert all(escapearg(k) == k for k in argsdict) + args = ','.join('%s=%s' % (escapearg(k), escapearg(v)) for k, v in argsdict.iteritems()) cmds.append('%s %s' % (op, args)) @@ -620,7 +625,7 @@ def batch(repo, proto, cmds, others): for a in args.split(','): if a: n, v = a.split('=') - vals[n] = unescapearg(v) + vals[unescapearg(n)] = unescapearg(v) func, spec = commands[op] if spec: keys = spec.split()