Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1174541
D243.id594.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
Thu, Oct 2, 4:01 PM
Size
1 KB
Mime Type
text/x-diff
Expires
Fri, Oct 3, 4:01 PM (12 h, 15 m)
Engine
blob
Format
Raw Data
Handle
761485
Attached To
D243: INP-1571 Form field validation should account for array-like field values
D243.id594.diff
View Options
Index: core/kernel/utility/validator.php
===================================================================
--- core/kernel/utility/validator.php
+++ core/kernel/utility/validator.php
@@ -228,8 +228,12 @@
{
$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 ) {
+ if ( isset($params['type'])
+ && preg_match('#int|integer|double|float|real#', $params['type'])
+ && $value_length > 0
+ ) {
// validate number
if ( isset($params['max_value_inc'])) {
$res = $res && $val <= $params['max_value_inc'];
@@ -264,14 +268,14 @@
return false;
}
- if ( strlen($val) > 0 ) {
+ if ( $value_length > 0 ) {
// Validate string.
if ( isset($params['max_len']) ) {
- $res = $res && mb_strlen($val) <= $params['max_len'];
+ $res = $res && $value_length <= $params['max_len'];
}
if ( isset($params['min_len']) ) {
- $res = $res && mb_strlen($val) >= $params['min_len'];
+ $res = $res && $value_length >= $params['min_len'];
}
}
@@ -279,7 +283,7 @@
$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);
Event Timeline
Log In to Comment