From ed12473b15b7c6025e31be755b025f60501781f6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerg=C5=91=20Tisza?= Date: Sat, 23 Apr 2016 16:35:15 +0000 Subject: [PATCH] Handle null data return in HTMLForm Fix a test in If4e0dfb : in the unlikely but valid case when some form field object returns null from loadDataFromRequest, handle it correctly and do not replace it with the default value. Bug: T133163 Change-Id: Id8b48cfc6288d11a79a5838e72bb80b14137a7b0 --- includes/htmlform/HTMLForm.php | 2 +- includes/htmlform/HTMLFormField.php | 6 +++--- includes/htmlform/HTMLFormFieldCloner.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index 2b6a0aa4fb..1d27c46171 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -1491,7 +1491,7 @@ class HTMLForm extends ContextSource { foreach ( $fields as $key => $value ) { if ( $value instanceof HTMLFormField ) { - $v = isset( $this->mFieldData[$key] ) + $v = array_key_exists( $key, $this->mFieldData ) ? $this->mFieldData[$key] : $value->getDefault(); diff --git a/includes/htmlform/HTMLFormField.php b/includes/htmlform/HTMLFormField.php index d5f4cc066f..d14fa90d94 100644 --- a/includes/htmlform/HTMLFormField.php +++ b/includes/htmlform/HTMLFormField.php @@ -117,8 +117,8 @@ abstract class HTMLFormField { $tmp = $m[1]; } if ( substr( $tmp, 0, 2 ) == 'wp' && - !isset( $alldata[$tmp] ) && - isset( $alldata[substr( $tmp, 2 )] ) + !array_key_exists( $tmp, $alldata ) && + array_key_exists( substr( $tmp, 2 ), $alldata ) ) { // Adjust for name mangling. $tmp = substr( $tmp, 2 ); @@ -139,7 +139,7 @@ abstract class HTMLFormField { $data = $alldata; while ( $keys ) { $key = array_shift( $keys ); - if ( !is_array( $data ) || !isset( $data[$key] ) ) { + if ( !is_array( $data ) || !array_key_exists( $key, $data ) ) { continue 2; } $data = $data[$key]; diff --git a/includes/htmlform/HTMLFormFieldCloner.php b/includes/htmlform/HTMLFormFieldCloner.php index 7359092176..3f80884bff 100644 --- a/includes/htmlform/HTMLFormFieldCloner.php +++ b/includes/htmlform/HTMLFormFieldCloner.php @@ -271,7 +271,7 @@ class HTMLFormFieldCloner extends HTMLFormField { $fields = $this->createFieldsForKey( $key ); foreach ( $fields as $fieldname => $field ) { - $v = isset( $values[$fieldname] ) + $v = array_key_exists( $fieldname, $values ) ? $values[$fieldname] : $field->getDefault(); -- 2.20.1