Question
It seems that one can't set a
WebPreferences variable to zero ('0'). It always evaluates to the empty string "". There's a fix in the Answer section, below.
- TWiki version: 01 Sep 2001 release
- Web server: Apache 1.3.x
- Server OS: Linux 2.2.14
- Web browser: Opera, Netscape, Mozilla, Lynx (all Linux)
- Client OS: Linux 2.2.14
--
TrippLilley - 15 Nov 2001
Answer
TWiki::Prefs::getPrefsFromTopic uses this Perl idiom when it's evaluating preference variable values:
$value = $2 || "";
The problem is that the assignment will fall through to the empty string ("") whenever $2 is false, which, by Perl's definition of "false", means whenever $2 is undefined, the empty string, or zero (0).
The fix is to check whether or not $2 is
defined, since that's the only case for which we really want to force the empty string:
$value = defined $2 ? $2 : "";
--
TrippLilley - 15 Nov 2001
Thanks for reporting. Copied it over to the Codev web as bug
Codev.VariablesCantBeSetToZero
--
PeterThoeny - 16 Nov 2001