Disable sources that contain an empty env. variable

This commit is contained in:
Sébastien Fourey 2023-04-01 10:50:37 +02:00
parent 4b586d1c89
commit 49457ec245
1 changed files with 9 additions and 2 deletions

View File

@ -79,7 +79,11 @@ QString GmicStdLib::substituteSourceVariables(QString text)
for (QRegularExpression re : reVariables) {
QRegularExpressionMatch match;
while ((match = re.match(text)).hasMatch()) {
text.replace(match.captured(0), QString::fromLocal8Bit(qgetenv(match.captured(1).toLocal8Bit().constData())));
QByteArray value = qgetenv(match.captured(1).toLocal8Bit().constData());
if (value.isEmpty()) { // Undefined variables should yield an ignored source
return {};
}
text.replace(match.captured(0), QString::fromLocal8Bit(value));
}
}
return text;
@ -89,7 +93,10 @@ QStringList GmicStdLib::substituteSourceVariables(const QStringList & list)
{
QStringList result;
for (const QString & str : list) {
result << substituteSourceVariables(str);
QString source = substituteSourceVariables(str);
if (!source.isEmpty()) {
result << source;
}
}
return result;
}