Skip to content

Commit 5cd6b6a

Browse files
18202781743yixinshark
authored andcommitted
fix: app crashed when parsing Actions for notification
as title. Log: as title. pms: TASK-366403
1 parent 48c425d commit 5cd6b6a

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

panels/notification/bubble/bubbleitem.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,18 @@ QVariantList BubbleItem::actions() const
243243
void BubbleItem::updateActions()
244244
{
245245
QStringList actions = m_entity.actions();
246-
const auto defaultIndex = actions.indexOf(QLatin1String("default"));
247-
if (defaultIndex >= 0) {
248-
actions.remove(defaultIndex, 2);
246+
if (actions.contains(QLatin1String("default"))) {
247+
actions.removeAll(QLatin1String("default"));
249248
m_defaultAction = QLatin1String("default");
250249
}
251250

251+
Q_ASSERT(actions.size() % 2 != 1);
252+
if (actions.size() % 2 == 1) {
253+
qWarning(notifyLog) << "Actions must be an even number except for default, The notify appName:" << m_entity.appName()
254+
<< ", actions:" << m_entity.actions();
255+
return;
256+
}
257+
252258
QVariantList array;
253259
for (int i = 0; i < actions.size(); i += 2) {
254260
const auto id = actions[i];

panels/notification/center/notifyitem.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,18 @@ QVariantList AppNotifyItem::actions() const
117117
void AppNotifyItem::updateActions()
118118
{
119119
QStringList actions = m_entity.actions();
120-
const auto defaultIndex = actions.indexOf(QLatin1String("default"));
121-
if (defaultIndex >= 0) {
122-
actions.remove(defaultIndex, 2);
120+
if (actions.contains(QLatin1String("default"))) {
121+
actions.removeAll(QLatin1String("default"));
123122
m_defaultAction = QLatin1String("default");
124123
}
125124

125+
Q_ASSERT(actions.size() % 2 != 1);
126+
if (actions.size() % 2 == 1) {
127+
qWarning(notifyLog) << "Actions must be an even number except for default, The notify appName:" << m_entity.appName()
128+
<< ", actions:" << m_entity.actions();
129+
return;
130+
}
131+
126132
QVariantList array;
127133
for (int i = 0; i < actions.size(); i += 2) {
128134
const auto id = actions[i];

0 commit comments

Comments
 (0)