[LON-CAPA-cvs] cvs: loncom /interface lonprintout.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 20 Oct 2006 17:37:22 -0000


albertel		Fri Oct 20 13:37:22 2006 EDT

  Modified files:              
    /loncom/interface	lonprintout.pm 
  Log:
  - if the subsitiontion string had a % in it could cause infinite loop.
    or malformed result
  
  
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.487 loncom/interface/lonprintout.pm:1.488
--- loncom/interface/lonprintout.pm:1.487	Tue Oct 17 05:56:16 2006
+++ loncom/interface/lonprintout.pm	Fri Oct 20 13:37:20 2006
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.487 2006/10/17 09:56:16 foxr Exp $
+# $Id: lonprintout.pm,v 1.488 2006/10/20 17:37:20 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -62,24 +62,17 @@
 sub printf_style_subst {
     my ($item, $format_string, $repl) = @_;
 
-    while ($format_string =~ /%\d*\Q$item\E/) {
-	my $start = $-[0];
-	my $end   = $+[0];
-	my $len   = $end - $start;
-
-	# see if we need to truncate:
-
+    while ($format_string =~m/\G[^%]*(%(\d*)\Q$item\E)/g) {
+	my $fmt = $1;
+	my $size = $2;
 	my $subst = $repl;
-	my $fmt   = substr($format_string, $start, $len);
-	my $size  = $fmt;
-	$size     =~ s/%(\d*)\Q$item\E/$1/;
 	if ($size ne "") {
 	    $subst = substr($subst, 0, $size);
 	}
-	$format_string =~ s/%(\d*)\Q$item\E/$subst/;
-
+	my $newpos =  pos($format_string) + length($subst) - length($fmt);
+	$format_string =~ s/\Q$fmt\E\G/$subst/;
+	pos($format_string)=$newpos;
     }
-
     return $format_string;
 }