FIX: the issue of arbitrary truncation in multibyte encoding in IsInPath(), the root cause of #2631

(cherry picked from commit b10bd5609f)
This commit is contained in:
rich2014 2025-12-03 18:18:53 +08:00 committed by Alexander Koblov
commit eb40b80116

View file

@ -752,12 +752,12 @@ begin
sBasePath := IncludeTrailingPathDelimiter(sBasePath);
BasePathLength := Length(sBasePath);
PathToCheckLength := Length(sPathToCheck);
BasePathLength := UTF8Length(sBasePath);
PathToCheckLength := UTF8Length(sPathToCheck);
if PathToCheckLength > BasePathLength then
begin
if mbCompareFileNames(Copy(sPathToCheck, 1, BasePathLength), sBasePath) then
if mbCompareFileNames(UTF8Copy(sPathToCheck, 1, BasePathLength), sBasePath) then
begin
if AllowSubDirs then
Result := True
@ -766,10 +766,10 @@ begin
// Additionally check if the remaining path is a relative path.
// Look for a path delimiter in the middle of the filepath.
sPathToCheck := Copy(sPathToCheck, 1 + BasePathLength,
sPathToCheck := UTF8Copy(sPathToCheck, 1 + BasePathLength,
PathToCheckLength - BasePathLength);
DelimiterPos := Pos(DirectorySeparator, sPathToCheck);
DelimiterPos := UTF8Pos(DirectorySeparator, sPathToCheck);
// If no delimiter was found or it was found at then end (directories
// may end with it), then the 'sPathToCheck' is in 'sBasePath'.
@ -784,7 +784,7 @@ begin
(((PathToCheckLength = BasePathLength) and
(mbCompareFileNames(sPathToCheck, sBasePath))) or
((PathToCheckLength = BasePathLength - 1) and
(mbCompareFileNames(Copy(sBasePath, 1, PathToCheckLength), sPathToCheck))));
(mbCompareFileNames(UTF8Copy(sBasePath, 1, PathToCheckLength), sPathToCheck))));
end;
function ExtractDirLevel(const sPrefix, sPath: String): String;