@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.

Throw when callers pass an invalid constraint to a "*.search" method

Summary:
Ref T11593. When you call a `*.search` method like `maniphest.search`, we don't currently validate that all the constraints you pass are recognized.

I think there were two very weak arguments for not doing this:

- It makes compatibility in `arc` across versions slightly easier: if we add a new constraint, we could add it to `arc` but also do client-side filtering for a while.
- Conduit parameter types //could//, in theory, accept multiple inputs or optional/alias inputs.

These reasons are pretty fluff and T11593 is a concrete issue caused by not validating. Just validate instead.

Test Plan:
- Made a `maniphest.search` call with a bogus constraint, got an explicit error about the bad constraint.
- Made a `maniphest.search` call with a valid constraint (`"ids"`).

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11593

Differential Revision: https://secure.phabricator.com/D16507

+28
+7
src/applications/conduit/parametertype/ConduitParameterType.php
··· 38 38 return $this->getParameterValue($request, $key); 39 39 } 40 40 41 + final public function getKeys($key) { 42 + return $this->getParameterKeys($key); 43 + } 41 44 42 45 final public function getDefaultValue() { 43 46 return $this->getParameterDefault(); ··· 84 87 85 88 protected function getParameterValue(array $request, $key) { 86 89 return $request[$key]; 90 + } 91 + 92 + protected function getParameterKeys($key) { 93 + return array($key); 87 94 } 88 95 89 96 abstract protected function getParameterTypeName();
+16
src/applications/search/engine/PhabricatorApplicationSearchEngine.php
··· 1094 1094 } 1095 1095 } 1096 1096 1097 + $valid_constraints = array(); 1098 + foreach ($fields as $field) { 1099 + foreach ($field->getValidConstraintKeys() as $key) { 1100 + $valid_constraints[$key] = true; 1101 + } 1102 + } 1103 + 1104 + foreach ($constraints as $key => $constraint) { 1105 + if (empty($valid_constraints[$key])) { 1106 + throw new Exception( 1107 + pht( 1108 + 'Constraint "%s" is not a valid constraint for this query.', 1109 + $key)); 1110 + } 1111 + } 1112 + 1097 1113 foreach ($fields as $field) { 1098 1114 if (!$field->getValueExistsInConduitRequest($constraints)) { 1099 1115 continue;
+5
src/applications/search/field/PhabricatorSearchField.php
··· 329 329 $this->getConduitKey()); 330 330 } 331 331 332 + public function getValidConstraintKeys() { 333 + return $this->getConduitParameterType()->getKeys( 334 + $this->getConduitKey()); 335 + } 336 + 332 337 333 338 /* -( Utility Methods )----------------------------------------------------- */ 334 339