From: Brad Jorsch Date: Tue, 21 Mar 2017 12:42:52 +0000 (-0400) Subject: Decode '0'-valued user options to integer 0 X-Git-Tag: 1.31.0-rc.0~3701^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/voir.php?a=commitdiff_plain;h=40f89f230ecc3f681424b9e31a7dde94e1e75820;p=lhc%2Fweb%2Fwiklou.git Decode '0'-valued user options to integer 0 I13d0e402f fixed a MySQL strict-mode bug by having boolean false be sent to the database as 0 rather than "", since so many of our logically-boolean fields are typed as tinyints. That happened to also cause logically-false user preferences to be stored in the user_properties table as "0" rather than "", which works fine in PHP but confuses JavaScript since it considers string-0 as truthy rather than falsey. To avoid this situation, convert "0" to 0 when loading the user options. Completely solving T54542 is left for another time, since identifying which type to normalize each option to seems nontrivial. Change-Id: Ia3280b7ce923641eac077141b47cba10d3fb88db --- diff --git a/includes/user/User.php b/includes/user/User.php index a963388188..ef4537f059 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -5266,6 +5266,13 @@ class User implements IDBAccessObject { $this->mOptionOverrides = []; $data = []; foreach ( $res as $row ) { + // Convert '0' to 0. PHP's boolean conversion considers them both + // false, but e.g. JavaScript considers the former as true. + // @todo: T54542 Somehow determine the desired type (string/int/bool) + // and convert all values here. + if ( $row->up_value === '0' ) { + $row->up_value = 0; + } $data[$row->up_property] = $row->up_value; } }