[LON-CAPA-cvs] cvs: loncom /homework edit.pm

raeburn raeburn@source.lon-capa.org
Wed, 10 Dec 2008 21:59:43 -0000


raeburn		Wed Dec 10 21:59:43 2008 EDT

  Modified files:              
    /loncom/homework	edit.pm 
  Log:
  - Sanity checking - check $list really is an arrayref.
  
  
Index: loncom/homework/edit.pm
diff -u loncom/homework/edit.pm:1.120 loncom/homework/edit.pm:1.121
--- loncom/homework/edit.pm:1.120	Wed Dec 10 21:45:31 2008
+++ loncom/homework/edit.pm	Wed Dec 10 21:59:43 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # edit mode helpers
 #
-# $Id: edit.pm,v 1.120 2008/12/10 21:45:31 bisitz Exp $
+# $Id: edit.pm,v 1.121 2008/12/10 21:59:43 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -871,21 +871,23 @@
     my $result;
     my $optionlist="";
     my $selected=$token->[2]{$name};
-    foreach my $option (@$list) {
-	my ($text,$value);
-	if ( ref($option) eq 'ARRAY') {
-	    $value='value="'.&HTML::Entities::encode($$option[0]).'"';
-	    $text=$$option[1];
-	    $option=$$option[0];
-	} else {
-	    $text=$option;
-	    $value='value="'.&HTML::Entities::encode($option,'\'"&<>').'"';
-	}
-	if ( $selected eq $option ) {
-	    $optionlist.="<option $value selected=\"selected\">".&mt($text)."</option>\n";
-	} else {
-	    $optionlist.="<option $value >".&mt($text)."</option>\n";
-	}
+    if (ref($list) eq 'ARRAY') {
+        foreach my $option (@{$list}) {
+	    my ($text,$value);
+	    if (ref($option) eq 'ARRAY') {
+	        $value='value="'.&HTML::Entities::encode($option->[0]).'"';
+	        $text=$option->[1];
+	        $option=$option->[0];
+	    } else {
+	        $text=$option;
+	        $value='value="'.&HTML::Entities::encode($option,'\'"&<>').'"';
+	    }
+	    if ( $selected eq $option ) {
+	        $optionlist.="<option $value selected=\"selected\">".&mt($text)."</option>\n";
+	    } else {
+	        $optionlist.="<option $value >".&mt($text)."</option>\n";
+	    }
+        }
     }
     $result.='<span class="LC_nobreak">'.&mt($description).'&nbsp;<select name="'.
 	&html_element_name($name).'" '.&element_change_detection().' >
@@ -900,22 +902,24 @@
     my $optionlist="";
     my $found=0;
     my $selected=$token->[2]{$name};
-    foreach my $option (@$list) {
-	my ($text,$value);
-	if ( ref($option) eq 'ARRAY') {
-	    $value='value="'.&HTML::Entities::encode($$option[0]).'"';
-	    $text=$$option[1];
-	    $option=$$option[0];
-	} else {
-	    $text=$option;
-	    $value='value="'.&HTML::Entities::encode($option,'\'"&<>').'"';
-	}
-	if ( $selected eq $option ) {
-	    $optionlist.="<option $value selected=\"selected\">$text</option>\n";
-	    $found=1;
-	} else {
-	    $optionlist.="<option $value>$text</option>\n";
-	}
+    if (ref($list) eq 'ARRAY') {
+        foreach my $option (@{$list}) {
+	    my ($text,$value);
+	    if (ref($option) eq 'ARRAY') {
+	        $value='value="'.&HTML::Entities::encode($option->[0]).'"';
+	        $text=$option->[1];
+	        $option=$option->[0];
+	    } else {
+	        $text=$option;
+	        $value='value="'.&HTML::Entities::encode($option,'\'"&<>').'"';
+	    }
+	    if ( $selected eq $option ) {
+	        $optionlist.="<option $value selected=\"selected\">$text</option>\n";
+	        $found=1;
+	    } else {
+	        $optionlist.="<option $value>$text</option>\n";
+	    }
+        }
     }
     $optionlist.="<option value=\"TYPEDINVALUE\"".
  	((!$found)?' selected="selected"':'').