Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15377490
D16694.id40187.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D16694.id40187.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
@@ -50,15 +50,7 @@
protected function validateStringList(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/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/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() {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Mar 14, 9:11 AM (1 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7652655
Default Alt Text
D16694.id40187.diff (6 KB)
Attached To
Mode
D16694: Conduit accept int/bool parameters as strings
Attached
Detach File
Event Timeline
Log In to Comment