From b8ae0f8da85e48236bba21177504eb4a4e64482a Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sun, 12 Jul 2009 20:44:00 +0000 Subject: [PATCH] Fix the if macro to recognize that 0 is a false value. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Macro/If.pm | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 6822caeb9..d894ed48b 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -2,6 +2,7 @@ - fixed #10629: WebGUI::ProfileField create new field bug - fixed #10626: Carriage returns stripped from Wiki comments - fixed #10572: CDN / CloudFront breaks 7.7.11 upgrade + - fixed #10630: If macro says that 0 is true 7.7.14 - fixed #10606: shelf selector diff --git a/lib/WebGUI/Macro/If.pm b/lib/WebGUI/Macro/If.pm index bf2dfe3dc..318c9c3cb 100644 --- a/lib/WebGUI/Macro/If.pm +++ b/lib/WebGUI/Macro/If.pm @@ -18,24 +18,23 @@ Package WebGUI::Macro::If =head1 DESCRIPTION -Macro for displaying text based on whether or not the value entered it empty. +Macro for displaying text based on whether or not the value entered is true. -=head2 process ( value, textIfValue, textIfNotValule ) - -Either the textIfValue or textIfNotValue fields can be empty +=head2 process ( value, textIfTrue, textIfFalse ) =head3 value -The value to test to see if it's empty. +The value to test to see if it's true or not. False values are the empty string, 0 and +any string which is only whitespace. -=head3 textIfValue +=head3 textIfTrue -The text to be displayed if the value is not empty. Use %s to represent the value itself. +The text to be displayed if the value is not false. Use %s to represent the value itself. -ex: ^HasValueText(test,
  • %s
  • ,); +ex: ^If(test,
  • %s
  • ,); returns:
  • test
  • -=head3 textIfNoValue +=head3 textIfFalse Text to be displayed if the value is empty. @@ -44,13 +43,13 @@ Text to be displayed if the value is empty. #------------------------------------------------------------------- sub process { my $session = shift; - my ($value, $valueText, $noValueText ) = @_; + my ($value, $trueText, $falseText ) = @_; $value =~ s/^\s//; $value =~ s/\s$//; - if ($value eq "") { - return $noValueText; + if (!$value) { + return $falseText; } - return sprintf($valueText,$value); + return sprintf($trueText,$value); }