@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Conduit: Fix PHP 8.1 "json_encode(null)" exception in differential.setdiffproperty

Summary:
Passing null to `json_encode()` is deprecated since PHP 8.1.

```
ERROR 8192: json_decode(): Passing null to parameter #1 ($json) of type string is deprecated at [/var/www/html/phorge/phorge/src/applications/differential/conduit/DifferentialSetDiffPropertyConduitAPIMethod.php:35]
```

In addition, also check for `name` not being null to avoid yet another similar AphrontQueryException here and throw a proper ConduitException instead.

Closes T16426

Test Plan:
* PHP 8.1+
* Go to http://phorge.localhost/conduit/method/differential.setdiffproperty/
* Press the "Call Method" button
* Go to http://phorge.localhost/conduit/method/differential.setdiffproperty/ and set `1` in the `diff_id` field and leave the `name` field empty
* Press the "Call Method" button

Reviewers: O1 Blessed Committers, mainframe98

Reviewed By: O1 Blessed Committers, mainframe98

Subscribers: mainframe98, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T16426

Differential Revision: https://we.phorge.it/D26637

+23 -2
+23 -2
src/applications/differential/conduit/DifferentialSetDiffPropertyConduitAPIMethod.php
··· 26 26 protected function defineErrorTypes() { 27 27 return array( 28 28 'ERR_NOT_FOUND' => pht('Diff was not found.'), 29 + 'ERR_NO_NAME' => pht('Name cannot be empty.'), 29 30 ); 30 31 } 31 32 32 33 protected function execute(ConduitAPIRequest $request) { 33 34 $diff_id = $request->getValue('diff_id'); 34 - $name = $request->getValue('name'); 35 - $data = json_decode($request->getValue('data'), true); 35 + if (!$diff_id) { 36 + throw new ConduitException('ERR_NOT_FOUND'); 37 + } 38 + $revision = id(new DifferentialDiffQuery()) 39 + ->setViewer($this->getViewer()) 40 + ->withIDs(array($diff_id)) 41 + ->requireCapabilities( 42 + array( 43 + PhabricatorPolicyCapability::CAN_VIEW, 44 + )) 45 + ->executeOne(); 46 + if (!$revision) { 47 + throw new ConduitException('ERR_NOT_FOUND'); 48 + } 36 49 50 + $name = $request->getValue('name'); 51 + if (!phutil_nonempty_string($name)) { 52 + throw new ConduitException('ERR_NO_NAME'); 53 + } 54 + $data = $request->getValue('data'); 55 + if ($data !== null) { 56 + $data = json_decode($data, true); 57 + } 37 58 self::updateDiffProperty($diff_id, $name, $data); 38 59 } 39 60