Skip to content

Commit

Permalink
Expand variables when locating files (#1022)
Browse files Browse the repository at this point in the history
  • Loading branch information
edocevoli committed Jan 15, 2022
1 parent 0d870ff commit b7e76a9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 22.1 - next release

### Fixed issues

- [1022](https://github.com/MiKTeX/miktex/issues/1022): expand variables when locating files

## 21.12.10 - 2021-12-10

### Upgraded programs
Expand Down
5 changes: 3 additions & 2 deletions Libraries/MiKTeX/Core/Session/findfile.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* findfile.cpp: finding files
Copyright (C) 1996-2021 Christian Schenk
Copyright (C) 1996-2022 Christian Schenk
This file is part of the MiKTeX Core Library.
Expand Down Expand Up @@ -382,8 +382,9 @@ bool SessionImpl::FindFileByType(const string& fileName, FileType fileType, bool
return !result.empty();
}

LocateResult MIKTEXTHISCALL SessionImpl::Locate(const string& fileName, const LocateOptions& options)
LocateResult MIKTEXTHISCALL SessionImpl::Locate(const string& givenFileName, const LocateOptions& options)
{
string fileName = this->ExpandValues(givenFileName, nullptr);
bool found = false;
vector<PathName> pathNames;
if (options.fileType == FileType::None)
Expand Down
16 changes: 15 additions & 1 deletion Libraries/MiKTeX/Core/test/fndb/1.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* 1.cpp:
Copyright (C) 1996-2021 Christian Schenk
Copyright (C) 1996-2022 Christian Schenk
This file is part of the MiKTeX Core Library.
Expand Down Expand Up @@ -30,6 +30,7 @@
#include <miktex/Core/File>
#include <miktex/Core/Fndb>
#include <miktex/Core/Paths>
#include <miktex/Core/Utils>
#include <miktex/Util/PathName>
#include <miktex/Util/StringUtil>

Expand Down Expand Up @@ -107,11 +108,24 @@ BEGIN_TEST_FUNCTION(3);
}
END_TEST_FUNCTION();

BEGIN_TEST_FUNCTION(4);
{
vector<PathName> paths;
MiKTeX::Core::Utils::SetEnvironmentString("ABRAKADABRA", "xyz");
TEST(pSession->FindFile("$ABRAKADABRA.txt", StringUtil::Flatten({ "%R/ab//", "%R/jk//" }, PathNameUtil::PathNameDelimiter), paths));
TEST(!paths.empty());
paths.clear();
TEST(pSession->FindFile("${ABRAKADABRA}.txt", StringUtil::Flatten({ "%R/ab//", "%R/jk//" }, PathNameUtil::PathNameDelimiter), paths));
TEST(!paths.empty());
}
END_TEST_FUNCTION();

BEGIN_TEST_PROGRAM();
{
CALL_TEST_FUNCTION(1);
CALL_TEST_FUNCTION(2);
CALL_TEST_FUNCTION(3);
CALL_TEST_FUNCTION(4);
}
END_TEST_PROGRAM();

Expand Down

0 comments on commit b7e76a9

Please sign in to comment.