Browse Source

* Fix from Kevin Jesshope to correct filename detection in CGI app

Michaël Van Canneyt 3 years ago
parent
commit
87ea9a9e0f
1 changed files with 12 additions and 3 deletions
  1. 12 3
      packages/fcl-web/src/base/fpwebfile.pp

+ 12 - 3
packages/fcl-web/src/base/fpwebfile.pp

@@ -30,6 +30,7 @@ Type
   TFPCustomFileModule = Class(TCustomHTTPModule)
   TFPCustomFileModule = Class(TCustomHTTPModule)
   private
   private
     FCacheControlMaxAge: Integer;
     FCacheControlMaxAge: Integer;
+    FScriptName:string;
   Protected
   Protected
     // Determine filename frome request.
     // Determine filename frome request.
     Function GetRequestFileName(Const ARequest : TRequest) : String; virtual;
     Function GetRequestFileName(Const ARequest : TRequest) : String; virtual;
@@ -299,19 +300,26 @@ end;
 Function TFPCustomFileModule.MapFileName(Const AFileName : String) : String; 
 Function TFPCustomFileModule.MapFileName(Const AFileName : String) : String; 
 
 
 Var
 Var
-  D : String;
+  D,localBaseURL : String;
 
 
 begin
 begin
   if (BaseURL='') then
   if (BaseURL='') then
     Result:=AFileName
     Result:=AFileName
   else
   else
     begin
     begin
-    D:=Locations.Values[BaseURL];
+    if FScriptName<>'' then
+      localBaseURL:=Copy(BaseURL,Length(FScriptName)+2,MaxInt)
+    else
+      localBaseURL:=BaseURL;
+    D:=Locations.Values[localBaseURL];
     If (D='') then
     If (D='') then
       Result:=''
       Result:=''
     else
     else
       begin
       begin
-      Result:=D+AFileName;
+      if FScriptName<>'' then
+        Result:=D+Copy(AFileName,Length(localBaseURL)+1,MaxInt)
+      else
+        Result:=D+AFileName;
       DoDirSeparators(Result);
       DoDirSeparators(Result);
       Result:=ExpandFileName(Result);
       Result:=ExpandFileName(Result);
       end;
       end;
@@ -374,6 +382,7 @@ Var
   RFN,FN : String;
   RFN,FN : String;
 
 
 begin
 begin
+  FScriptName:=ARequest.ScriptName;
   If CompareText(ARequest.Method,'GET')<>0 then
   If CompareText(ARequest.Method,'GET')<>0 then
     begin
     begin
     AResponse.SetStatus(405,True);
     AResponse.SetStatus(405,True);