Преглед изворни кода

* do not blindly insert decimal seperators in StrToFloat, resolves #27029

git-svn-id: trunk@29126 -
florian пре 10 година
родитељ
комит
9a31cba3d3
3 измењених фајлова са 22 додато и 4 уклоњено
  1. 1 0
      .gitattributes
  2. 10 4
      rtl/objpas/sysutils/sysstr.inc
  3. 11 0
      tests/webtbs/tw27029.pp

+ 1 - 0
.gitattributes

@@ -14119,6 +14119,7 @@ tests/webtbs/tw26976.pp svneol=native#text/plain
 tests/webtbs/tw26993.pp svneol=native#text/plain
 tests/webtbs/tw26993a.pp svneol=native#text/plain
 tests/webtbs/tw2702.pp svneol=native#text/plain
+tests/webtbs/tw27029.pp svneol=native#text/pascal
 tests/webtbs/tw2703.pp svneol=native#text/plain
 tests/webtbs/tw2704.pp svneol=native#text/plain
 tests/webtbs/tw2705.pp svneol=native#text/plain

+ 10 - 4
rtl/objpas/sysutils/sysstr.inc

@@ -1327,10 +1327,16 @@ Begin
         { Delete leading spaces }
         while Result[1] = ' ' do
           System.Delete(Result, 1, 1);
-        if Result[1] = '-' then
-          Result[3] := DS
-        else
-          Result[2] := DS;
+
+        { not Nan etc.? }
+        if Pos('.', Result)<>0 then
+          begin
+            if Result[1] = '-' then
+              Result[3] := DS
+            else
+              Result[2] := DS;
+          end;
+
         P:=Pos('E',Result);
         if P <> 0 then
           begin

+ 11 - 0
tests/webtbs/tw27029.pp

@@ -0,0 +1,11 @@
+uses
+  sysutils, math;
+
+begin
+  DecimalSeparator:=',';
+  if FloatToStrF(nan, ffExponent, 15, 1)<>'Nan' then
+    halt(1);
+  if FloatToStrF(1.3, ffExponent, 15, 1)[2]<>',' then
+    halt(1);
+  writeln('ok');
+end.