From: Gergő Tisza Date: Sat, 23 Apr 2016 16:35:15 +0000 (+0000) Subject: Handle null data return in HTMLForm X-Git-Tag: 1.31.0-rc.0~7179^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=ed12473b15b7c6025e31be755b025f60501781f6;p=lhc%2Fweb%2Fwiklou.git 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 --- 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();