[freeside-commits] freeside/FS/FS/UI bytecount.pm,1.1.2.4,1.1.2.5

Jeff Finucane,420,, jeff at wavetail.420.am
Wed Oct 3 19:06:55 PDT 2007


Update of /home/cvs/cvsroot/freeside/FS/FS/UI
In directory wavetail:/tmp/cvs-serv13399/FS/FS/UI

Modified Files:
      Tag: FREESIDE_1_7_BRANCH
	bytecount.pm 
Log Message:
support part_pkg option input validation, check bytecounts and allow commas (closes 1863)

Index: bytecount.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/UI/bytecount.pm,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -d -r1.1.2.4 -r1.1.2.5
--- bytecount.pm	26 Apr 2007 03:35:58 -0000	1.1.2.4
+++ bytecount.pm	4 Oct 2007 02:06:53 -0000	1.1.2.5
@@ -42,20 +42,21 @@
 
 Accepts a number (digits and a decimal point) possibly followed by k, m, g, or
 t (and an optional 'b') in either case.  Returns a pure number representing
-the input or the input itself if unparsable.
+the input or the input itself if unparsable.  Discards commas as noise.
 
 =cut
 
 sub parse_bytecount {
   my $bc = shift;
   return $bc if (($bc =~ tr/.//) > 1);
-  $bc =~ /^\s*([\d.]*)\s*([kKmMgGtT]?)[bB]?\s*$/ or return $bc;
+  $bc =~ /^\s*([,\d.]*)\s*([kKmMgGtT]?)[bB]?\s*$/ or return $bc;
   my $base = $1;
+  $base =~ tr/,//d;
   return $bc unless length $base;
   my $exponent = index ' kmgt', lc($2);
   return $bc if ($exponent < 0 && $2);
   $exponent = 0 if ($exponent < 0);
-  return $base * 1024 ** $exponent;
+  return int($base * 1024 ** $exponent);  #bytecounts are integer values
 }
 
 =item display_bytecount AMOUNT



More information about the freeside-commits mailing list