Skip to content

Commit dd94e2e

Browse files
committed
Addressing PHP8 incompatibilities - Conduit
Summary: Navigate through all the conduit pages and address PHP8 incompatibilities. Additionally test out empty form submissions on many of the "create" or "update" APIs and return more contextual errors rather than PHP8 errors. Refs T13588 Test Plan: - Clicked through all the conduit APIs. - Clicked submit on empty forms, or minimally filled-in forms. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley, PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13588 Differential Revision: https://secure.phabricator.com/D21872
1 parent 6015847 commit dd94e2e

18 files changed

+58
-13
lines changed

src/applications/differential/conduit/DifferentialCreateDiffConduitAPIMethod.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ protected function defineReturnType() {
5555
protected function execute(ConduitAPIRequest $request) {
5656
$viewer = $request->getUser();
5757
$change_data = $request->getValue('changes');
58+
if ($change_data === null) {
59+
throw new Exception(pht('Field "changes" must be non-empty.'));
60+
}
5861

5962
$changes = array();
6063
foreach ($change_data as $dict) {

src/applications/differential/conduit/DifferentialCreateRawDiffConduitAPIMethod.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ protected function defineReturnType() {
2626
protected function execute(ConduitAPIRequest $request) {
2727
$viewer = $request->getUser();
2828
$raw_diff = $request->getValue('diff');
29+
if ($raw_diff === null || !strlen($raw_diff)) {
30+
throw new Exception(pht('Field "raw_diff" must be non-empty.'));
31+
}
2932

3033
$repository_phid = $request->getValue('repositoryPHID');
3134
if ($repository_phid) {

src/applications/differential/conduit/DifferentialParseCommitMessageConduitAPIMethod.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ protected function execute(ConduitAPIRequest $request) {
3333
}
3434

3535
$corpus = $request->getValue('corpus');
36+
if ($corpus === null || !strlen($corpus)) {
37+
throw new Exception(pht('Field "corpus" must be non-empty.'));
38+
}
3639
$field_map = $parser->parseFields($corpus);
3740

3841
$errors = $parser->getErrors();

src/applications/differential/conduit/DifferentialSetDiffPropertyConduitAPIMethod.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,22 @@ protected function defineErrorTypes() {
3030
}
3131

3232
protected function execute(ConduitAPIRequest $request) {
33+
$data = $request->getValue('data');
34+
if ($data === null || !strlen($data)) {
35+
throw new Exception(pht('Field "data" must be non-empty.'));
36+
}
37+
3338
$diff_id = $request->getValue('diff_id');
39+
if ($diff_id === null) {
40+
throw new Exception(pht('Field "diff_id" must be non-null.'));
41+
}
42+
3443
$name = $request->getValue('name');
35-
$data = json_decode($request->getValue('data'), true);
44+
if ($name === null || !strlen($name)) {
45+
throw new Exception(pht('Field "name" must be non-empty.'));
46+
}
47+
48+
$data = json_decode($data, true);
3649

3750
self::updateDiffProperty($diff_id, $name, $data);
3851
}

src/applications/differential/editor/DifferentialTransactionEditor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ protected function expandTransaction(
218218

219219
// No "$", to allow for branches like T123_demo.
220220
$match = null;
221-
if (preg_match('/^T(\d+)/i', $branch, $match)) {
221+
if ($branch !== null && preg_match('/^T(\d+)/i', $branch, $match)) {
222222
$task_id = $match[1];
223223
$tasks = id(new ManiphestTaskQuery())
224224
->setViewer($this->getActor())

src/applications/files/conduit/FileUploadConduitAPIMethod.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ protected function execute(ConduitAPIRequest $request) {
3131
$view_policy = $request->getValue('viewPolicy');
3232

3333
$data = $request->getValue('data_base64');
34+
if ($data === null) {
35+
throw new Exception(pht('Field "data_base64" must be non-empty.'));
36+
}
3437
$data = $this->decodeBase64($data);
3538

3639
$params = array(

src/applications/harbormaster/conduit/HarbormasterSendMessageConduitAPIMethod.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,15 +515,15 @@ protected function execute(ConduitAPIRequest $request) {
515515
}
516516
}
517517

518-
if (!strlen($receiver_name)) {
518+
if ($receiver_name === null || !strlen($receiver_name)) {
519519
throw new Exception(
520520
pht(
521521
'Call omits required "receiver" parameter. Specify the PHID '.
522522
'of the object you want to send a message to.'));
523523
}
524524

525525
$message_type = $request->getValue('type');
526-
if (!strlen($message_type)) {
526+
if ($message_type === null || !strlen($message_type)) {
527527
throw new Exception(
528528
pht(
529529
'Call omits required "type" parameter. Specify the type of '.

src/applications/harbormaster/editor/HarbormasterBuildPlanEditEngine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected function buildCustomEditFields($object) {
103103
$key);
104104
$behavior_option = $object->getPlanProperty($storage_key);
105105

106-
if (!strlen($behavior_option)) {
106+
if ($behavior_option === null || !strlen($behavior_option)) {
107107
$behavior_option = $behavior->getPlanOption($object)->getKey();
108108
}
109109

src/applications/paste/conduit/PasteCreateConduitAPIMethod.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function execute(ConduitAPIRequest $request) {
4343
$title = $request->getValue('title');
4444
$language = $request->getValue('language');
4545

46-
if (!strlen($content)) {
46+
if ($content === null || !strlen($content)) {
4747
throw new ConduitException('ERR-NO-PASTE');
4848
}
4949

src/applications/phriction/conduit/PhrictionCreateConduitAPIMethod.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ protected function defineReturnType() {
2525

2626
protected function execute(ConduitAPIRequest $request) {
2727
$slug = $request->getValue('slug');
28-
if (!strlen($slug)) {
29-
throw new Exception(pht('No such document.'));
28+
if ($slug === null || !strlen($slug)) {
29+
throw new Exception(pht('Field "slug" must be non-empty.'));
3030
}
31+
3132
$doc = id(new PhrictionDocumentQuery())
3233
->setViewer($request->getUser())
3334
->withSlugs(array(PhabricatorSlug::normalize($slug)))

0 commit comments

Comments
 (0)