fix: unescape exec before pass this arg to wordexp

Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
ComixHe
2023-10-19 14:18:44 +08:00
committed by Comix
parent 5597ba5c44
commit f796535233
5 changed files with 98 additions and 27 deletions

47
tests/ut_escapeexec.cpp Normal file
View File

@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "dbus/applicationservice.h"
#include <gtest/gtest.h>
#include <QString>
TEST(UnescapeExec, blankSpace)
{
QList<std::pair<QString, QList<QString>>> testCases{
{
R"(/usr/bin/hello\sworld --arg1=val1 -h --str="rrr ggg bbb")",
{
"/usr/bin/hello world",
"--arg1=val1",
"-h",
"--str=rrr ggg bbb",
},
},
{
R"("/usr/bin/hello world" a b -- "c d")",
{
"/usr/bin/hello world",
"a",
"b",
"--",
"c d",
},
},
{
R"("/usr/bin/hello\t\nworld" a b -- c d)",
{
"/usr/bin/hello\t\nworld",
"a",
"b",
"--",
"c",
"d",
},
},
};
for (auto &testCase : testCases) {
EXPECT_EQ(ApplicationService::unescapeExecArgs(testCase.first), testCase.second);
}
}