[PATCH STABLE] phabricator: properly encode boolean types in the request body

Yuya Nishihara yuya at tcha.org
Sat Dec 22 02:44:57 EST 2018


On Fri, 21 Dec 2018 18:15:40 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison at yahoo.com>
> # Date 1545431772 18000
> #      Fri Dec 21 17:36:12 2018 -0500
> # Node ID 366889e199653dad6052970c48a2bd2ae62e5e1d
> # Parent  6f483b107eb5ee100d8a308cb6216da576fc4c41
> phabricator: properly encode boolean types in the request body
> 
> I tripped over this playing with `hg debugcallconduit` to query for valid
> reviewers.  If the JSON on stdin is written as 'True' or 'False', python
> complains it isn't valid JSON.  If it's written as 'true' or 'false', it made it
> to the server, but got kicked back with this:
> 
>     abort: Conduit Error (ERR-CONDUIT-CORE): Error while reading "isBot":
>            Expected boolean (true or false), got something else.
> 
> The test isn't really relevant here (the code can be reverted, and it will
> pass), but this gives us coverage for the debug command.
> 
> diff --git a/hgext/phabricator.py b/hgext/phabricator.py
> --- a/hgext/phabricator.py
> +++ b/hgext/phabricator.py
> @@ -160,6 +160,8 @@ def urlencodenested(params):
>              flatparams[prefix] = obj
>          else:
>              for k, v in items(obj):
> +                if isinstance(v, bool):
> +                    v = { True: b'true', False: b'false' }[v]

It's probably better to consolidate this into the main type dispatch.

  if isinstance(obj, bool):
      obj = <convert obj to PHP-compatible notation>
  ...


More information about the Mercurial-devel mailing list