Forum OpenACS Development: Bug in template::data::validate::boolean

Hi

I noticed an odd bug in template::data::validate::boolean. It always returns 1 because when it calls "string tolower", it seems to be calling the "string" command in the  template::data::validate namespace, rather than the standard TCL one.

One fix is to prefix the call to "string tolower" with :: but I'd like opinions if that is the best fix.

Here's my fixed version:

ad_proc -public template::data::validate::boolean {
value_ref
message_ref
} {
Validates boolean data types.

@author Roberto Mello <rmello at fslc.usu.edu>

@param value_ref Reference variable to the submitted value
@param message_ref Reference variable for returning an error message

@return True (1) if valid, false (0) if not
} {

upvar 2 $message_ref message $value_ref value

set result ""
set value [::string tolower $value]

switch $value {
    0 -
    1 -
    f -
    t -
    n -
    y -
    no -
    yes -
    false -
    true {
        set result 1
    }
    default {
        set result 0
        set message "Invalid choice \"$value\""
    }
}

return $result
}

Collapse
Posted by Gustaf Neumann on
Brian, many thanks, fixed in CVS. The fix will be available as well after the nightly build soon via "upgrade from repository".

The same construct with ::string was already in place for template::data::validate::textdate

all the best
-g

Collapse
Posted by Brian Fenton on
Thanks for the quick response, Gustaf!