[LON-CAPA-cvs] cvs: loncom /homework structuretags.pm /xml lonxml.pm

albertel lon-capa-cvs-allow@mail.lon-capa.org
Tue, 16 Oct 2007 23:20:26 -0000


albertel		Tue Oct 16 19:20:26 2007 EDT

  Modified files:              
    /loncom/xml	lonxml.pm 
    /loncom/homework	structuretags.pm 
  Log:
  - BUG#5481, throw errors in CSTR when the are extraneous unnested startoutext/endouttext tags
  
  
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.464 loncom/xml/lonxml.pm:1.465
--- loncom/xml/lonxml.pm:1.464	Wed Oct 10 10:39:49 2007
+++ loncom/xml/lonxml.pm	Tue Oct 16 19:20:05 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.464 2007/10/10 14:39:49 albertel Exp $
+# $Id: lonxml.pm,v 1.465 2007/10/16 23:20:05 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -631,6 +631,24 @@
   return $currentstring;
 }
 
+{
+    my %state;
+
+    sub init_state {
+	undef(%state);
+    }
+    
+    sub set_state {
+	my ($key,$value) = @_;
+	$state{$key} = $value;
+	return $value;
+    }
+    sub get_state {
+	my ($key) = @_;
+	return $state{$key};
+    }
+}
+
 sub setup_globals {
   my ($request,$target)=@_;
   $Apache::lonxml::request=$request;
@@ -640,6 +658,7 @@
   $Apache::lonxml::usestyle=1;
   &init_counter();
   &clear_bubble_lines_for_part();
+  &init_state();
   @Apache::lonxml::pwd=();
   @Apache::lonxml::extlinks=();
   @script_var_displays=();
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.403 loncom/homework/structuretags.pm:1.404
--- loncom/homework/structuretags.pm:1.403	Fri Oct 12 14:45:47 2007
+++ loncom/homework/structuretags.pm	Tue Oct 16 19:20:25 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.403 2007/10/12 18:45:47 albertel Exp $
+# $Id: structuretags.pm,v 1.404 2007/10/16 23:20:25 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1747,6 +1747,13 @@
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     my @result=(''.'');
     if ($target eq 'edit' || $target eq 'modified' ) { @result=('','no'); }
+    
+    my $nesting = 
+	&Apache::lonxml::set_state('outtext',
+				   &Apache::lonxml::get_state('outtext')+1);
+    if ($nesting > 1 && $env{'request.state'} eq 'construct') {
+	&Apache::lonxml::error("Nesting of <startouttext /> not allowed, on line ".$token->[5]);
+    }
     return (@result);
 }
 
@@ -1786,6 +1793,14 @@
 	$result='<endouttext />'.
 	    &Apache::edit::handle_insertafter('startouttext');
     }
+
+    my $nesting = 
+	&Apache::lonxml::set_state('outtext',
+				   &Apache::lonxml::get_state('outtext')-1);
+    if ($nesting < 0 && $env{'request.state'} eq 'construct') {
+	&Apache::lonxml::error(" Extraneous &lt;endouttext /&gt; not allowed on line ".$token->[5]);
+	&Apache::lonxml::set_state('outtext', 0);
+    }
     return $result;
 }