mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 05:40:54 -06:00
cmStringCommand: clear intermediate matches
When `string(REGEX REPLACE)` or `string(REGEX MATCHALL)` loop internally, they store their matches, but they do not clear the previous match from an earlier iteration. This can leave the contents of `CMAKE_MATCH_<N>` with bogus values for later matches in the string if they have groups which earlier matched a non-empty string, but now match an empty string. Fixes #17079.
This commit is contained in:
@@ -309,6 +309,7 @@ bool cmStringCommand::RegexMatchAll(std::vector<std::string> const& args)
|
||||
std::string output;
|
||||
const char* p = input.c_str();
|
||||
while (re.find(p)) {
|
||||
this->Makefile->ClearMatches();
|
||||
this->Makefile->StoreMatches(re);
|
||||
std::string::size_type l = re.start();
|
||||
std::string::size_type r = re.end();
|
||||
@@ -391,6 +392,7 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
|
||||
std::string output;
|
||||
std::string::size_type base = 0;
|
||||
while (re.find(input.c_str() + base)) {
|
||||
this->Makefile->ClearMatches();
|
||||
this->Makefile->StoreMatches(re);
|
||||
std::string::size_type l2 = re.start();
|
||||
std::string::size_type r = re.end();
|
||||
|
||||
Reference in New Issue
Block a user