diff hgext/phabricator.py @ 41017:d7d3164e6a31 stable

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.
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 21 Dec 2018 17:36:12 -0500
parents 7e2c58b08e74
children 46e0563c67db
line wrap: on
line diff
--- a/hgext/phabricator.py	Tue Dec 11 22:34:07 2018 +0900
+++ b/hgext/phabricator.py	Fri Dec 21 17:36:12 2018 -0500
@@ -155,6 +155,8 @@
     """
     flatparams = util.sortdict()
     def process(prefix, obj):
+        if isinstance(obj, bool):
+            obj = {True: b'true', False: b'false'}[obj]  # Python -> PHP form
         items = {list: enumerate, dict: lambda x: x.items()}.get(type(obj))
         if items is None:
             flatparams[prefix] = obj