Moodle
  1. Moodle
  2. MDL-3623

Choice doesn't like 1 or 0 as choice text

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: 1.5
    • Fix Version/s: None
    • Component/s: Choice
    • Labels:
      None
    • Environment:
      All
    • Affected Branches:
      MOODLE_15_STABLE
    • Rank:
      14438

      Description

      If you use the single digit 1 (one) as the text for any of the choice options then, the option text will not be displayed above the users who selected it.

      This happens both if you make the responses public to the user, and when the Tutor views the results.

      Other single digit numbers work fine except for 0 that triggers a different effect. The option completely disappears, the same as if the text entry area was left completely blank.

        Activity

        Hide
        Martin Dougiamas added a comment -

        From Howard Miller (howard.miller at udcf.gla.ac.uk) Friday, 24 June 2005, 04:37 PM:

        I had a quick look - The '1' issue is something to do with caching. The format_string() routine always finds the md5 of text string '1' in the cache array and returns a blank. I'm not sure why.

        From Howard Miller (howard.miller at udcf.gla.ac.uk) Friday, 24 June 2005, 04:50 PM:

        Thinking some more... what about simply not returning an empty string from the cache... it is is empty go ahead and process the original string the 'hard way'.....

        (note extra test for emptiness after 'fetch from cache if possible')

        function format_string ($string, $striplinks = false, $courseid=NULL ) {

        global $CFG, $course;

        //We'll use a in-memory cache here to speed up repeated strings

        static $strcache;

        //Calculate md5

        $md5 = md5($string.$striplinks);

        //Fetch from cache if possible

        if(isset($strcache[$md5])) {

        $cache_string = $strcache[$md5];

        if ($cache_string)

        { return $cache_string; }

        }

        From Howard Miller (howard.miller at udcf.gla.ac.uk) Friday, 24 June 2005, 05:16 PM:

        ...and the '0' is a results of this...

        if ($value) {....

        in function choice_update_instance($choice) in choice lib.php.

        This sort of thing is all over the place, so it might well have to be a 'feature'.

        From Dan Marsden (dan at digitalclay.co.nz) Monday, 27 June 2005, 04:18 AM:

        Hi Howard, thanks for checking this out! - I'm going to cc Eloy, he's given me some good feedback about format_string before....

        Dan

        From Eloy Lafuente (stronk7 at moodle.org) Monday, 27 June 2005, 08:31 AM:

        Hi,

        curious bug. It was really hard to trace!

        the format_string() functions calculates the md5 of the string passed concatenated with true or false (boolean).

        It was happening that, with this call: format_string('',true), the function was calculating the md5 of ''.true, i.e, the md5 of true, i.e, the md5 of 1.

        Then, when the 1 string was going called: format_string('1',false), the function was looking for the md5 of '1' and, as it existed, it returned its cached value, i.e ''.

        I've modified the format_string() function slightly and the '1' problem shouldn't be present anymore.

        About the '0' value, perhaps the check should be changed (as 0) is a correct option, checking if it's set, instead of checking if it has a non-false value.

        Ciao

        PD: Cool bug! :-P

        From Dan Marsden (dan at digitalclay.co.nz) Monday, 27 June 2005, 08:39 AM:

        Thanks Eloy!!!

        From Dan Marsden (dan at digitalclay.co.nz) Monday, 27 June 2005, 09:09 AM:

        I've just updated Choice\view.php and choice\lib.php to check isset($value) - Public cvs will take a while to be updated. These changes are in 1_5_STABLE and HEAD

        1_5_STABLE:

        lib.php,v 1.28.2.1 2005/06/27 01:03:50 danmarsden

        view.php,v 1.69.2.1 2005/06/27 01:03:50 danmarsden

        HEAD:

        lib.php,v 1.29 2005/06/27 00:58:24 danmarsden

        view.php,v 1.71 2005/06/27 00:58:24 danmarsden

        this fixes the '0' issue - Eloy has fixed the '1' issue.

        Dan

        Show
        Martin Dougiamas added a comment - From Howard Miller (howard.miller at udcf.gla.ac.uk) Friday, 24 June 2005, 04:37 PM: I had a quick look - The '1' issue is something to do with caching. The format_string() routine always finds the md5 of text string '1' in the cache array and returns a blank. I'm not sure why. From Howard Miller (howard.miller at udcf.gla.ac.uk) Friday, 24 June 2005, 04:50 PM: Thinking some more... what about simply not returning an empty string from the cache... it is is empty go ahead and process the original string the 'hard way'..... (note extra test for emptiness after 'fetch from cache if possible') function format_string ($string, $striplinks = false, $courseid=NULL ) { global $CFG, $course; //We'll use a in-memory cache here to speed up repeated strings static $strcache; //Calculate md5 $md5 = md5($string.$striplinks); //Fetch from cache if possible if(isset($strcache [$md5] )) { $cache_string = $strcache [$md5] ; if ($cache_string) { return $cache_string; } } From Howard Miller (howard.miller at udcf.gla.ac.uk) Friday, 24 June 2005, 05:16 PM: ...and the '0' is a results of this... if ($value) {.... in function choice_update_instance($choice) in choice lib.php. This sort of thing is all over the place, so it might well have to be a 'feature'. From Dan Marsden (dan at digitalclay.co.nz) Monday, 27 June 2005, 04:18 AM: Hi Howard, thanks for checking this out! - I'm going to cc Eloy, he's given me some good feedback about format_string before.... Dan From Eloy Lafuente (stronk7 at moodle.org) Monday, 27 June 2005, 08:31 AM: Hi, curious bug. It was really hard to trace! the format_string() functions calculates the md5 of the string passed concatenated with true or false (boolean). It was happening that, with this call: format_string('',true), the function was calculating the md5 of ''.true, i.e, the md5 of true, i.e, the md5 of 1. Then, when the 1 string was going called: format_string('1',false), the function was looking for the md5 of '1' and, as it existed, it returned its cached value, i.e ''. I've modified the format_string() function slightly and the '1' problem shouldn't be present anymore. About the '0' value, perhaps the check should be changed (as 0) is a correct option, checking if it's set, instead of checking if it has a non-false value. Ciao PD: Cool bug! :-P From Dan Marsden (dan at digitalclay.co.nz) Monday, 27 June 2005, 08:39 AM: Thanks Eloy!!! From Dan Marsden (dan at digitalclay.co.nz) Monday, 27 June 2005, 09:09 AM: I've just updated Choice\view.php and choice\lib.php to check isset($value) - Public cvs will take a while to be updated. These changes are in 1_5_STABLE and HEAD 1_5_STABLE: lib.php,v 1.28.2.1 2005/06/27 01:03:50 danmarsden view.php,v 1.69.2.1 2005/06/27 01:03:50 danmarsden HEAD: lib.php,v 1.29 2005/06/27 00:58:24 danmarsden view.php,v 1.71 2005/06/27 00:58:24 danmarsden this fixes the '0' issue - Eloy has fixed the '1' issue. Dan

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: