Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions panels/notification/common/notifyentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Q_LOGGING_CATEGORY(notifyLog, "dde.shell.notification")
#define ACTION_SEGMENT ("|")
#define HINT_SEGMENT ("|")
#define KEY_VALUE_SEGMENT ("!!!")
#define LIST_VALUE_SEGMENT (":::")

static const uint NoReplaceId = 0;

Expand Down Expand Up @@ -294,7 +295,13 @@ QString NotifyEntity::convertHintsToString(const QVariantMap &map)
QString key = it.key();
text += key;
text += KEY_VALUE_SEGMENT;
QString value = it.value().toString();
QString value;
if (it.value().typeId() == QMetaType::QStringList) {
QStringList tmp = it.value().toStringList();
value = tmp.join(LIST_VALUE_SEGMENT);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Delimiter may appear in data and break parsing

Consider escaping LIST_VALUE_SEGMENT in list elements or using a safer serialization method like JSON or base64 to prevent parsing errors.

} else {
value = it.value().toString();
}
text += value;
text += HINT_SEGMENT;
}
Expand Down Expand Up @@ -328,7 +335,13 @@ QVariantMap NotifyEntity::parseHint(const QString &hint)
if (list.size() != 2)
continue;
const QString &key = list[0];
QVariant value = QVariant::fromValue(list[1]);
QVariant value;
auto listValue = list[1].split(LIST_VALUE_SEGMENT);
if (listValue.size() > 1) {
value = QVariant::fromValue(listValue);
} else {
value = QVariant::fromValue(list[1]);
}

map.insert(key, value);
}
Expand Down
9 changes: 8 additions & 1 deletion panels/notification/server/notificationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,14 @@ void NotificationManager::doActionInvoked(const NotifyEntity &entity, const QStr
QMap<QString, QVariant>::const_iterator i = hints.constBegin();
while (i != hints.constEnd()) {
if (i.key() == "x-deepin-action-" + actionId) {
QStringList args = i.value().toString().split(",");
QStringList args;
if (i.value().typeId() == QMetaType::QStringList) {
args = i.value().toStringList();
} else {
qDebug(notifyLog) << "Deprecate hint format, use string list instead of string."
<< "actionId:" << actionId << ", value:" << i.value();
args = i.value().toString().split(",");
}
if (!args.isEmpty()) {
QString cmd = args.takeFirst(); // 命令

Expand Down