Handle null data return in HTMLForm
authorGergő Tisza <gtisza@wikimedia.org>
Sat, 23 Apr 2016 16:35:15 +0000 (16:35 +0000)
committerGergő Tisza <tgr.huwiki@gmail.com>
Mon, 25 Apr 2016 23:27:22 +0000 (01:27 +0200)
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
includes/htmlform/HTMLFormField.php
includes/htmlform/HTMLFormFieldCloner.php

index 2b6a0aa..1d27c46 100644 (file)
@@ -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();
 
index d5f4cc0..d14fa90 100644 (file)
@@ -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];
index 7359092..3f80884 100644 (file)
@@ -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();