Fix: directory change to non-normalized paths - issue #130 (#1061)

(cherry picked from commit 273759d119)
This commit is contained in:
Demetrius flavious 2023-09-09 17:19:41 +03:00 committed by Alexander Koblov
commit 4e2506d9f2
2 changed files with 14 additions and 3 deletions

View file

@ -396,11 +396,16 @@ const
AllowPathDelimiters : set of char = ['\','/'];
var
I : LongInt;
uriPos : Integer;
begin
Result:= Path;
// If path is not URI
if Pos('://', Result) = 0 then
begin
uriPos := Pos('://', Result);
if (uriPos = 0)
{$IF DEFINED(MSWINDOWS)}
or ( (uriPos = 2) and (Path[1] in ['A'..'z']) )
{$ENDIF} then
begin
for I:= 1 to Length(Path) do
if Path[I] in AllowPathDelimiters then
Result[I]:= DirectorySeparator;

View file

@ -358,13 +358,19 @@ end;
function mbExpandFileName(const sFileName: String): String;
begin
if (Pos('://', sFileName) > 0) then
if (Pos('://', sFileName) > 2) then
Result:= sFileName
else begin
Result:= NormalizePathDelimiters(sFileName);
Result:= ReplaceEnvVars(Result);
if Pos(PathDelim, Result) <> 0 then
Result:= ExpandFileName(Result);
{$IF DEFINED(MSWINDOWS)}
// Remove double backslash '\\' after calling 'ExpandFileName'
if (Pos(':\\', Result) = 2) and (Result[1] in ['A'..'z']) then
Result:= Result.Remove(2, 1);
{$ENDIF}
end;
end;