Mercurial > hg
comparison mercurial/wireproto.py @ 29734:62e2e048d068
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.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 06 Aug 2016 13:55:21 -0700 |
parents | bb04f96df51c |
children | 919a4b7f531d |
comparison
equal
deleted
inserted
replaced
29733:bb04f96df51c | 29734:62e2e048d068 |
---|---|
189 | 189 |
190 def encodebatchcmds(req): | 190 def encodebatchcmds(req): |
191 """Return a ``cmds`` argument value for the ``batch`` command.""" | 191 """Return a ``cmds`` argument value for the ``batch`` command.""" |
192 cmds = [] | 192 cmds = [] |
193 for op, argsdict in req: | 193 for op, argsdict in req: |
194 # Old servers didn't properly unescape argument names. So prevent | |
195 # the sending of argument names that may not be decoded properly by | |
196 # servers. | |
197 assert all(escapearg(k) == k for k in argsdict) | |
198 | |
194 args = ','.join('%s=%s' % (escapearg(k), escapearg(v)) | 199 args = ','.join('%s=%s' % (escapearg(k), escapearg(v)) |
195 for k, v in argsdict.iteritems()) | 200 for k, v in argsdict.iteritems()) |
196 cmds.append('%s %s' % (op, args)) | 201 cmds.append('%s %s' % (op, args)) |
197 | 202 |
198 return ';'.join(cmds) | 203 return ';'.join(cmds) |
618 op, args = pair.split(' ', 1) | 623 op, args = pair.split(' ', 1) |
619 vals = {} | 624 vals = {} |
620 for a in args.split(','): | 625 for a in args.split(','): |
621 if a: | 626 if a: |
622 n, v = a.split('=') | 627 n, v = a.split('=') |
623 vals[n] = unescapearg(v) | 628 vals[unescapearg(n)] = unescapearg(v) |
624 func, spec = commands[op] | 629 func, spec = commands[op] |
625 if spec: | 630 if spec: |
626 keys = spec.split() | 631 keys = spec.split() |
627 data = {} | 632 data = {} |
628 for k in keys: | 633 for k in keys: |