Преглед на файлове

* fixed StrToDate to throw proper exceptions in case of an error, fixes bug #3913

git-svn-id: trunk@156 -
florian преди 20 години
родител
ревизия
4f30642b4a
променени са 3 файла, в които са добавени 31 реда и са изтрити 3 реда
  1. 1 0
      .gitattributes
  2. 5 3
      rtl/objpas/sysutils/dati.inc
  3. 25 0
      tests/webtbs/tw3913.pp

+ 1 - 0
.gitattributes

@@ -6112,6 +6112,7 @@ tests/webtbs/tw3893.pp svneol=native#text/plain
 tests/webtbs/tw3898.pp svneol=native#text/plain
 tests/webtbs/tw3899.pp svneol=native#text/plain
 tests/webtbs/tw3900.pp svneol=native#text/plain
+tests/webtbs/tw3913.pp svneol=native#text/plain
 tests/webtbs/tw3939.pp svneol=native#text/plain
 tests/webtbs/tw3953a.pp svneol=native#text/plain
 tests/webtbs/tw3953b.pp svneol=native#text/plain

+ 5 - 3
rtl/objpas/sysutils/dati.inc

@@ -369,7 +369,7 @@ begin
    begin
      if (s[i] in ['0'..'9']) then
       s1 := s1 + s[i];
-     if (s[i] in [dateseparator,' ']) or (i = length(s)) then
+     if (s[i] in [dateseparator,' ']) or ((i = length(s)) and (s[i] in ['0'..'9'])) then
       begin
         inc(n);
         if n>3 then
@@ -378,7 +378,9 @@ begin
         if c<>0 then
          Raise EConvertError.Create('Invalid date format');
         s1 := '';
-      end ;
+      end
+     else if not (s[i] in ['0'..'9']) then
+      Raise EConvertError.Create('Invalid date format');
    end ;
   // Fill in values.
   getLocalTime(LocalTime);
@@ -416,7 +418,7 @@ begin
     if (TwoDigitYearCenturyWindow > 0) and (Y < ly) then
       Inc(Y, 100);
     end;
-  Result := DoEncodeDate(y, m, d);
+  Result := EncodeDate(y, m, d);
 end ;
 
 

+ 25 - 0
tests/webtbs/tw3913.pp

@@ -0,0 +1,25 @@
+{ $mode objfpc}
+uses
+  sysutils;
+var
+  d : tdatetime;
+begin
+  try
+    d:=strtodate('03'+dateseparator+'03'+dateseparator+'2033');
+  except
+    halt(1);
+  end;
+  writeln(1);
+  try
+    d:=strtodate('2.2/2');
+    halt(1);
+  except
+  end;
+  writeln(2);
+  try
+    d:=strtodate('33'+dateseparator+'33'+dateseparator+'33');
+    halt(1);
+  except
+  end;
+  writeln('ok');
+end.