Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F804033
D243.id867.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Feb 26, 9:04 AM
Size
2 KB
Mime Type
text/x-diff
Expires
Thu, Feb 27, 9:04 AM (4 h, 59 m)
Engine
blob
Format
Raw Data
Handle
576747
Attached To
D243: INP-1571 Form field validation should account for array-like field values
D243.id867.diff
View Options
Index: core/kernel/utility/validator.php
===================================================================
--- core/kernel/utility/validator.php
+++ core/kernel/utility/validator.php
@@ -228,10 +228,15 @@
{
$res = true;
$val = $this->dataSource->GetDBField($field);
+ $value_length = is_scalar($val) ? mb_strlen($val) : 0;
- if ( isset($params['type']) && preg_match("#int|integer|double|float|real#", $params['type']) && strlen($val) > 0 ) {
- // validate number
- if ( isset($params['max_value_inc'])) {
+ if ( !$value_length ) {
+ return true;
+ }
+
+ if ( isset($params['type']) && preg_match('#int|integer|double|float|real#', $params['type']) ) {
+ // Validate number.
+ if ( isset($params['max_value_inc']) ) {
$res = $res && $val <= $params['max_value_inc'];
$max_val = $params['max_value_inc'].' (inclusive)';
}
@@ -250,43 +255,44 @@
$res = $res && $val > $params['min_value_exc'];
$min_val = $params['min_value_exc'].' (exclusive)';
}
- }
- if ( !$res ) {
- if ( !isset($min_val) ) $min_val = '-∞';
- if ( !isset($max_val) ) $max_val = '∞';
+ if ( !$res ) {
+ if ( !isset($min_val) ) {
+ $min_val = '-∞';
+ }
- $this->SetError($field, 'value_out_of_range', null, array(
- 'min_value' => $min_val,
- 'max_value' => $max_val
- ));
+ if ( !isset($max_val) ) {
+ $max_val = '∞';
+ }
- return false;
+ $this->SetError($field, 'value_out_of_range', null, array(
+ 'min_value' => $min_val,
+ 'max_value' => $max_val,
+ ));
+ }
+
+ return $res;
}
- if ( strlen($val) > 0 ) {
- // Validate string.
- if ( isset($params['max_len']) ) {
- $res = $res && mb_strlen($val) <= $params['max_len'];
- }
+ // Validate string.
+ if ( isset($params['max_len']) ) {
+ $res = $res && $value_length <= $params['max_len'];
+ }
- if ( isset($params['min_len']) ) {
- $res = $res && mb_strlen($val) >= $params['min_len'];
- }
+ if ( isset($params['min_len']) ) {
+ $res = $res && $value_length >= $params['min_len'];
}
if ( !$res ) {
$error_params = array(
'min_length' => (int)getArrayValue($params, 'min_len'),
'max_length' => (int)getArrayValue($params, 'max_len'),
- 'value' => mb_strlen($val)
+ 'value' => $value_length,
);
$this->SetError($field, 'length_out_of_range', null, $error_params);
-
- return false;
}
- return true;
+ return $res;
}
/**
Event Timeline
Log In to Comment