Browse Source

* Correctly handle missing extensions for dotted include file names. Fixes issue #41064

Michaël Van Canneyt 7 months ago
parent
commit
5632af2afa
3 changed files with 24 additions and 9 deletions
  1. 12 9
      compiler/scanner.pas
  2. 3 0
      tests/webtbs/iwb41064.msg.pp
  3. 9 0
      tests/webtbs/twb41064.pp

+ 12 - 9
compiler/scanner.pas

@@ -1884,7 +1884,7 @@ type
 
 
         function preproc_factor(eval: Boolean):texprvalue;
         function preproc_factor(eval: Boolean):texprvalue;
         var
         var
-           hs,countstr,storedpattern: string;
+           hs,countstr,storedpattern,fileext: string;
            mac: tmacro;
            mac: tmacro;
            srsym : tsym;
            srsym : tsym;
            srsymtable : TSymtable;
            srsymtable : TSymtable;
@@ -1920,15 +1920,16 @@ type
 
 
                     { try to find the file, this like 'include' }
                     { try to find the file, this like 'include' }
                     found:=findincludefile(path,name,foundfile);
                     found:=findincludefile(path,name,foundfile);
-                    if (not found) and (ExtractFileExt(name)='') then
+                    fileext:=lower(ExtractFileExt(name));
+                    if (not found) and ((fileext<>'.inc') and (fileext<>sourceext) and (fileext<>pasext)) then
                      begin
                      begin
                        { try default extensions .inc , .pp and .pas }
                        { try default extensions .inc , .pp and .pas }
                        if (not found) then
                        if (not found) then
-                        found:=findincludefile(path,ChangeFileExt(name,'.inc'),foundfile);
+                        found:=findincludefile(path,name+'.inc',foundfile);
                        if (not found) then
                        if (not found) then
-                        found:=findincludefile(path,ChangeFileExt(name,sourceext),foundfile);
+                        found:=findincludefile(path,name+sourceext,foundfile);
                        if (not found) then
                        if (not found) then
-                        found:=findincludefile(path,ChangeFileExt(name,pasext),foundfile);
+                        found:=findincludefile(path,name+pasext,foundfile);
                      end;
                      end;
                     if (not found) and (ExtractFileExt(name)=ExtensionSeparator) and (Length(name)>=2) then
                     if (not found) and (ExtractFileExt(name)=ExtensionSeparator) and (Length(name)>=2) then
                       found:=findincludefile(path,Copy(name,1,Length(name)-1),foundfile);
                       found:=findincludefile(path,Copy(name,1,Length(name)-1),foundfile);
@@ -2752,6 +2753,7 @@ type
         hp    : tinputfile;
         hp    : tinputfile;
         found : boolean;
         found : boolean;
         macroIsString : boolean;
         macroIsString : boolean;
+        fileext: string;
       begin
       begin
         current_scanner.skipspace;
         current_scanner.skipspace;
         args:=current_scanner.readcomment;
         args:=current_scanner.readcomment;
@@ -2856,15 +2858,16 @@ type
 
 
            { try to find the file }
            { try to find the file }
            found:=findincludefile(path,name,foundfile);
            found:=findincludefile(path,name,foundfile);
-           if (not found) and (ExtractFileExt(name)='') then
+           fileext:=lower(ExtractFileExt(name));
+           if (not found) and ((fileext<>'.inc') and (fileext<>sourceext) and (fileext<>pasext)) then
             begin
             begin
               { try default extensions .inc , .pp and .pas }
               { try default extensions .inc , .pp and .pas }
               if (not found) then
               if (not found) then
-               found:=findincludefile(path,ChangeFileExt(name,'.inc'),foundfile);
+               found:=findincludefile(path,name+'.inc',foundfile);
               if (not found) then
               if (not found) then
-               found:=findincludefile(path,ChangeFileExt(name,sourceext),foundfile);
+               found:=findincludefile(path,name+sourceext,foundfile);
               if (not found) then
               if (not found) then
-               found:=findincludefile(path,ChangeFileExt(name,pasext),foundfile);
+               found:=findincludefile(path,name+pasext,foundfile);
             end;
             end;
            { if the name ends in dot, try without the dot }
            { if the name ends in dot, try without the dot }
            if (not found) and (ExtractFileExt(name)=ExtensionSeparator) and (Length(name)>=2) then
            if (not found) and (ExtractFileExt(name)=ExtensionSeparator) and (Length(name)>=2) then

+ 3 - 0
tests/webtbs/iwb41064.msg.pp

@@ -0,0 +1,3 @@
+const
+  Hello = 'Hello world!';
+  

+ 9 - 0
tests/webtbs/twb41064.pp

@@ -0,0 +1,9 @@
+program project1;
+
+{$I iwb41064.msg}
+
+begin
+  writeln(Hello);
+  readln;
+end.
+