Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15479457
D16694.id40188.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D16694.id40188.diff
View Options
diff --git a/src/applications/conduit/parametertype/ConduitBoolParameterType.php b/src/applications/conduit/parametertype/ConduitBoolParameterType.php
--- a/src/applications/conduit/parametertype/ConduitBoolParameterType.php
+++ b/src/applications/conduit/parametertype/ConduitBoolParameterType.php
@@ -5,15 +5,7 @@
protected function getParameterValue(array $request, $key) {
$value = parent::getParameterValue($request, $key);
-
- if (!is_bool($value)) {
- $this->raiseValidationException(
- $request,
- $key,
- pht('Expected boolean (true or false), got something else.'));
- }
-
- return $value;
+ return $this->parseBoolValue($request, $key, $value);
}
protected function getParameterTypeName() {
diff --git a/src/applications/conduit/parametertype/ConduitEpochParameterType.php b/src/applications/conduit/parametertype/ConduitEpochParameterType.php
--- a/src/applications/conduit/parametertype/ConduitEpochParameterType.php
+++ b/src/applications/conduit/parametertype/ConduitEpochParameterType.php
@@ -5,13 +5,7 @@
protected function getParameterValue(array $request, $key) {
$value = parent::getParameterValue($request, $key);
-
- if (!is_int($value)) {
- $this->raiseValidationException(
- $request,
- $key,
- pht('Expected epoch timestamp as integer, got something else.'));
- }
+ $value = $this->parseIntValue($request, $key, $value);
if ($value <= 0) {
$this->raiseValidationException(
diff --git a/src/applications/conduit/parametertype/ConduitIntListParameterType.php b/src/applications/conduit/parametertype/ConduitIntListParameterType.php
--- a/src/applications/conduit/parametertype/ConduitIntListParameterType.php
+++ b/src/applications/conduit/parametertype/ConduitIntListParameterType.php
@@ -7,15 +7,7 @@
$list = parent::getParameterValue($request, $key);
foreach ($list as $idx => $item) {
- if (!is_int($item)) {
- $this->raiseValidationException(
- $request,
- $key,
- pht(
- 'Expected a list of integers, but item with index "%s" is '.
- 'not an integer.',
- $idx));
- }
+ $list[$idx] = $this->parseIntValue($request, $key.'['.$idx.']', $item);
}
return $list;
diff --git a/src/applications/conduit/parametertype/ConduitIntParameterType.php b/src/applications/conduit/parametertype/ConduitIntParameterType.php
--- a/src/applications/conduit/parametertype/ConduitIntParameterType.php
+++ b/src/applications/conduit/parametertype/ConduitIntParameterType.php
@@ -5,15 +5,7 @@
protected function getParameterValue(array $request, $key) {
$value = parent::getParameterValue($request, $key);
-
- if (!is_int($value)) {
- $this->raiseValidationException(
- $request,
- $key,
- pht('Expected integer, got something else.'));
- }
-
- return $value;
+ return $this->parseIntValue($request, $key, $value);
}
protected function getParameterTypeName() {
diff --git a/src/applications/conduit/parametertype/ConduitListParameterType.php b/src/applications/conduit/parametertype/ConduitListParameterType.php
--- a/src/applications/conduit/parametertype/ConduitListParameterType.php
+++ b/src/applications/conduit/parametertype/ConduitListParameterType.php
@@ -48,17 +48,9 @@
return $value;
}
- protected function validateStringList(array $request, $key, array $list) {
+ protected function parseStringList(array $request, $key, array $list) {
foreach ($list as $idx => $item) {
- if (!is_string($item)) {
- $this->raiseValidationException(
- $request,
- $key,
- pht(
- 'Expected a list of strings, but item with index "%s" is '.
- 'not a string.',
- $idx));
- }
+ $list[$idx] = $this->parseStringValue($request, $key.'['.$idx.']', $item);
}
return $list;
diff --git a/src/applications/conduit/parametertype/ConduitPHIDListParameterType.php b/src/applications/conduit/parametertype/ConduitPHIDListParameterType.php
--- a/src/applications/conduit/parametertype/ConduitPHIDListParameterType.php
+++ b/src/applications/conduit/parametertype/ConduitPHIDListParameterType.php
@@ -5,7 +5,7 @@
protected function getParameterValue(array $request, $key) {
$list = parent::getParameterValue($request, $key);
- return $this->validateStringList($request, $key, $list);
+ return $this->parseStringList($request, $key, $list);
}
protected function getParameterTypeName() {
diff --git a/src/applications/conduit/parametertype/ConduitParameterType.php b/src/applications/conduit/parametertype/ConduitParameterType.php
--- a/src/applications/conduit/parametertype/ConduitParameterType.php
+++ b/src/applications/conduit/parametertype/ConduitParameterType.php
@@ -93,6 +93,53 @@
return array($key);
}
+ protected function parseStringValue(array $request, $key, $value) {
+ if (!is_string($value)) {
+ $this->raiseValidationException(
+ $request,
+ $key,
+ pht('Expected string, got something else.'));
+ }
+ return $value;
+ }
+
+ protected function parseIntValue(array $request, $key, $value) {
+ if (is_string($value) && ctype_digit($value)) {
+ $value = $value + 0;
+ if (!is_int($value)) {
+ $this->raiseValidationException(
+ $request,
+ $key,
+ pht('Integer overflow.'));
+ }
+ } else if (!is_int($value)) {
+ $this->raiseValidationException(
+ $request,
+ $key,
+ pht('Expected integer, got something else.'));
+ }
+ return $value;
+ }
+
+ protected function parseBoolValue(array $request, $key, $value) {
+ $bool_strings = array(
+ '0' => false,
+ '1' => true,
+ 'false' => false,
+ 'true' => true,
+ );
+
+ if (is_string($value) && isset($bool_strings[$value])) {
+ $value = $bool_strings[$value];
+ } else if (!is_bool($value)) {
+ $this->raiseValidationException(
+ $request,
+ $key,
+ pht('Expected boolean (true or false), got something else.'));
+ }
+ return $value;
+ }
+
abstract protected function getParameterTypeName();
diff --git a/src/applications/conduit/parametertype/ConduitProjectListParameterType.php b/src/applications/conduit/parametertype/ConduitProjectListParameterType.php
--- a/src/applications/conduit/parametertype/ConduitProjectListParameterType.php
+++ b/src/applications/conduit/parametertype/ConduitProjectListParameterType.php
@@ -5,7 +5,7 @@
protected function getParameterValue(array $request, $key) {
$list = parent::getParameterValue($request, $key);
- $list = $this->validateStringList($request, $key, $list);
+ $list = $this->parseStringList($request, $key, $list);
return id(new PhabricatorProjectPHIDResolver())
->setViewer($this->getViewer())
->resolvePHIDs($list);
diff --git a/src/applications/conduit/parametertype/ConduitStringListParameterType.php b/src/applications/conduit/parametertype/ConduitStringListParameterType.php
--- a/src/applications/conduit/parametertype/ConduitStringListParameterType.php
+++ b/src/applications/conduit/parametertype/ConduitStringListParameterType.php
@@ -5,7 +5,7 @@
protected function getParameterValue(array $request, $key) {
$list = parent::getParameterValue($request, $key);
- return $this->validateStringList($request, $key, $list);
+ return $this->parseStringList($request, $key, $list);
}
protected function getParameterTypeName() {
diff --git a/src/applications/conduit/parametertype/ConduitStringParameterType.php b/src/applications/conduit/parametertype/ConduitStringParameterType.php
--- a/src/applications/conduit/parametertype/ConduitStringParameterType.php
+++ b/src/applications/conduit/parametertype/ConduitStringParameterType.php
@@ -5,15 +5,7 @@
protected function getParameterValue(array $request, $key) {
$value = parent::getParameterValue($request, $key);
-
- if (!is_string($value)) {
- $this->raiseValidationException(
- $request,
- $key,
- pht('Expected string, got something else.'));
- }
-
- return $value;
+ return $this->parseStringValue($request, $key, $value);
}
protected function getParameterTypeName() {
diff --git a/src/applications/conduit/parametertype/ConduitUserListParameterType.php b/src/applications/conduit/parametertype/ConduitUserListParameterType.php
--- a/src/applications/conduit/parametertype/ConduitUserListParameterType.php
+++ b/src/applications/conduit/parametertype/ConduitUserListParameterType.php
@@ -5,7 +5,7 @@
protected function getParameterValue(array $request, $key) {
$list = parent::getParameterValue($request, $key);
- $list = $this->validateStringList($request, $key, $list);
+ $list = $this->parseStringList($request, $key, $list);
return id(new PhabricatorUserPHIDResolver())
->setViewer($this->getViewer())
->resolvePHIDs($list);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Apr 9, 7:24 AM (5 d, 17 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7737630
Default Alt Text
D16694.id40188.diff (8 KB)
Attached To
Mode
D16694: Conduit accept int/bool parameters as strings
Attached
Detach File
Event Timeline
Log In to Comment