Browse Source

* Fix remaining cases of startsstr. Fixes issue #41085

Michaël Van Canneyt 1 tháng trước cách đây
mục cha
commit
609d8bef90

+ 11 - 5
packages/fcl-web/src/base/fphttpclient.pp

@@ -443,6 +443,12 @@ function DecodeURLElement(const S: UnicodeString): UnicodeString;
 
 implementation
 
+{$IFDEF FPC_DOTTEDUNITS}
+uses System.StrUtils;
+{$ELSE}
+uses StrUtils;
+{$ENDIF}
+
 resourcestring
   SErrInvalidProtocol = 'Invalid protocol : "%s"';
   SErrReadingSocket = 'Error reading data from socket';
@@ -1023,7 +1029,7 @@ Var
 
 begin
   S:=Uppercase(GetNextWord(AStatusLine));
-  If (Copy(S,1,5)<>'HTTP/') then
+  If StartsStr('HTTP/',S) then
     Raise EHTTPClient.CreateFmt(SErrInvalidProtocolVersion,[S]);
   System.Delete(S,1,5);
   FServerHTTPVersion:=S;
@@ -1071,7 +1077,7 @@ begin
     if ReadString(S) and (S<>'') then
       begin
       ResponseHeaders.Add(S);
-      If (LowerCase(Copy(S,1,Length(SetCookie)))=SetCookie) then
+      If StartsText(SetCookie,S) then
         DoCookies(S);
       end
   Until (S='') or Terminated;
@@ -1117,7 +1123,7 @@ begin
   While (Result=-1) and (I<FResponseHeaders.Count) do
     begin
     S:=Trim(LowerCase(FResponseHeaders[i]));
-    If (Copy(S,1,Length(Cl))=Cl) then
+    If StartsStr(Cl,S) then
       begin
       System.Delete(S,1,Length(CL));
       Result:=StrToInt64Def(Trim(S),-1);
@@ -1141,7 +1147,7 @@ begin
   While (I<FResponseHeaders.Count) do
     begin
     S:=Trim(LowerCase(FResponseHeaders[i]));
-    If (Copy(S,1,Length(Cl))=Cl) then
+    If StartsStr(Cl,S) then
       begin
       System.Delete(S,1,Length(CL));
       Result:=Trim(S);
@@ -1582,7 +1588,7 @@ begin
   H:=LowerCase(Aheader)+':';
   l:=Length(H);
   Result:=HTTPHeaders.Count-1;
-  While (Result>=0) and ((LowerCase(Copy(HTTPHeaders[Result],1,l)))<>h) do
+  While (Result>=0) and not StartsText(H,HTTPHeaders[Result]) do
     Dec(Result);
 end;
 

+ 3 - 3
packages/fcl-web/src/base/fpmimetypes.pp

@@ -22,10 +22,10 @@ interface
 
 {$IFDEF FPC_DOTTEDUNITS}
 uses
-  System.Classes, System.SysUtils, System.Contnrs;
+  System.Classes, System.SysUtils, System.Contnrs, System.StrUtils;
 {$ELSE FPC_DOTTEDUNITS}
 uses
-  Classes, SysUtils, contnrs;
+  Classes, SysUtils, contnrs, strutils;
 {$ENDIF FPC_DOTTEDUNITS}
 
 Type
@@ -443,7 +443,7 @@ begin
       if (Fextensions<>'') then
         If Fextensions[Length(FExtensions)]<>';' then
           FExtensions:=FExtensions+';';
-      If (Copy(Fextensions,1,Length(E))<>E) and (Pos(E,FExtensions)=0) then
+      If (Not StartsStr(E,Fextensions)) and (Pos(E,FExtensions)=0) then
         FExtensions:=Extensions+E;
       end;
   Until (E='')