Closed mmr99869 closed 8 years ago
Hey, thank you for reporting the issue.
I think we need to force the creation of an empty object by using JSON_FORCE_OBJECT
, e.g.
json_encode(array_pop($this->request), JSON_FORCE_OBJECT);
This should generate {}
instead of []
for the empty $ticket_data['attr'] = array();
Please modify the code (https://github.com/jakoch/PHPTracRPC/blob/master/lib/TracRPC.php#L1177) and give me a feedback, if this works for you.
Hi jakoch,
I tried what you explained about forcing the creation of an empty object inside TracRPC.php:
$this->request = json_encode(array_pop($this->request), JSON_FORCE_OBJECT);
However, it did not work. The generated JSON object contains the following:
{
"method": "system.multicall",
"params": {
"0" : {
"method": "ticket.create",
"params": {
"0" : "The ticket summary text",
"1" : "The ticket description text",
"2" : {},
"3" : false
},
"id": 1
}
},
"id": 1
}
When sending the request, Trac returns a JSON error:
{
"result": null,
"error": {
"name": "JSONRPCError",
"message": "JsonProtocolException details : 'unicode' object has no attribute 'get'",
"code": -32700
},
"id": 1
}
For now, what is working for me is to keep the old json_encode(...)
code and adding a validation after it:
$this->request = json_encode(array_pop($this->request));
// (...)
$this->request = str_replace('[]', '{}', $this->request);
Thank you for providing your solution. I've applied your patch and released a new version. https://github.com/jakoch/PHPTracRPC/releases/tag/1.0.0
I hope the issue is resolved. Closing.
Hi everyone,
I had an issue with PHPTracRPC when creating Trac tickets. Specifically, when I have an empty "attr" data array:
If executed, the above code will produce the following JSON error response:
I analyzed a little bit the PHPTracRPC code and I found the problem when encoding the request in JSON. It seems that empty "attr" data array produces "[]" instead of "{}":
The produced
$ticket_data
JSON request is:When changing "[]" to "{}" the problem dissappears. When using a keyed and filled "attr" data array the problem also dissappears.
Maybe this is a bug?