fix: incorrect behavior when parse and launch

Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
ComixHe 2023-08-25 18:21:11 +08:00 committed by Comix
parent 3988e0c526
commit ce2148e5cd
4 changed files with 17 additions and 8 deletions

View File

@ -377,6 +377,7 @@ LaunchTask ApplicationService::unescapeExec(const QString &str, const QStringLis
auto matcher = re.match(str);
if (!matcher.hasMatch()) {
task.command.append(std::move(execList));
task.Resources.emplace_back(QString{""}); // mapReduce should run once at least
return task;
}

View File

@ -21,7 +21,7 @@ bool isInvalidLocaleString(const QString &str) noexcept
constexpr auto Language = R"((?:[a-z]+))"; // language of locale postfix. eg.(en, zh)
constexpr auto Country = R"((?:_[A-Z]+))"; // country of locale postfix. eg.(US, CN)
constexpr auto Encoding = R"((?:\.[0-9A-Z-]+))"; // encoding of locale postfix. eg.(UFT-8)
constexpr auto Modifier = R"((?:@[a-z=;]+))"; // modifier of locale postfix. eg.(euro;collation=traditional)
constexpr auto Modifier = R"((?:@[a-zA-Z=;]+))"; // modifier of locale postfix. eg.(euro;collation=traditional)
const static auto validKey = QString(R"(^%1%2?%3?%4?$)").arg(Language, Country, Encoding, Modifier);
// example: https://regex101.com/r/hylOay/2
static const QRegularExpression _re = []() -> QRegularExpression {
@ -75,7 +75,7 @@ private:
void Parser::skip() noexcept
{
while (!m_stream.atEnd() and (m_line.startsWith('#') or m_line.isEmpty())) {
m_line = m_stream.readLine();
m_line = m_stream.readLine().trimmed();
}
}
@ -137,6 +137,9 @@ DesktopErrorCode Parser::addGroup(Groups &ret) noexcept
m_line.clear();
while (!m_stream.atEnd() && !m_line.startsWith('[')) {
skip();
if (m_line.startsWith('[')) {
break;
}
auto err = addEntry(group);
if (err != DesktopErrorCode::NoError) {
return err;
@ -198,7 +201,12 @@ DesktopErrorCode Parser::addEntry(Groups::iterator &group) noexcept
return DesktopErrorCode::NoError;
}
group->insert(key, {{localeStr, valueStr}});
if (keyIt == group->end()) {
group->insert(key, {{localeStr, valueStr}});
return DesktopErrorCode::NoError;
}
keyIt->insert(localeStr, valueStr);
return DesktopErrorCode::NoError;
}
@ -482,7 +490,9 @@ QString DesktopEntry::Value::toString(bool &ok) const noexcept
{
ok = false;
auto str = this->find(defaultKeyStr);
if (str == this->end()) {
qWarning() << "value not found.";
return {};
}

View File

@ -69,10 +69,8 @@ void applyIteratively(QList<QDir> dirs, T &&func)
continue;
}
const auto &infoList =
dir.entryInfoList({"*.desktop"},
QDir::Readable | QDir::AllDirs | QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot,
QDir::Name | QDir::DirsLast);
const auto &infoList = dir.entryInfoList(
{"*.desktop"}, QDir::Readable | QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot, QDir::Name | QDir::DirsLast);
for (const auto &info : infoList) {
if (info.isFile() and func(info)) {

View File

@ -55,7 +55,7 @@ GenericName[es]=Editor de texto
GenericName[et]=Tekstiredaktor
GenericName[fi]=Tekstieditori
GenericName[fr]=Éditeur de texte
GenericName[en_US.UTF-8@euro;collation=traditional]=just for test\;teststing=abab\;
GenericName[en_US.UTF-8@euro]=just for test\;teststing=abab\;
GenericName[gl_ES]=Editor de texto
GenericName[hr]=Uređivač teksta
GenericName[hu]=Szövegszerkesztő