fix(dde-apps): return empty list when firstNItems count <= 0 - #1715
fix(dde-apps): return empty list when firstNItems count <= 0#1715MyLeeJiEun wants to merge 2 commits into
Conversation
ItemsPage::firstNItems(count) appended an item before checking result.count() >= count, so firstNItems(0) (and any count <= 0) returned the first item instead of an empty list. Add an early return for count <= 0 before the loop. count > 0 behavior is unchanged (no regression). The method has no current callers, so this is an API-contract fix only. Ref: DDE-144
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: MyLeeJiEun The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideFixes the firstNItems contract for count <= 0 by returning an empty QStringList before iteration, while preserving behavior for all positive counts. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Hi @MyLeeJiEun. Thanks for your PR. I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
问题描述
dde-shell的applets/dde-apps/itemspage.cpp方法ItemsPage::firstNItems(int count)存在语义缺陷:count = 0(及任意count <= 0)时返回首项而非空列表,违反firstNItems(0)应返回空的直觉契约。缺陷根因
循环内先
result.append(item)再判result.count() >= count:count = 0时:第一次迭代append("a")→result.count()变 1 →1 >= 0为 true → 返回["a"](首项),而非预期的空列表。count < 0(如-1)也返回首项(1 >= -1为 true)。修复内容
在
QStringList result;之后、循环之前新增早返逻辑,对count <= 0直接返回空列表:不采用「先判后 append」方案——会改变
count恰好为页边界时的返回项数(少取一项),引入回归。修复效果
firstNItems(0)→[]✅(修复前返回首项)firstNItems(-1)→[]✅(修复前返回首项)firstNItems(2/3/10)等正数行为完全不变 ✅(无回归)影响范围
applets/dde-apps/itemspage.cpp一处,2 行新增。count > 0路径逻辑一字未改,无回归风险。firstNItems调用点为 0,方法仅声明未使用,生产路径无触发风险,属 API 契约级修复。审核
count > 0路径无回归、无副作用、代码风格与既有写法一致)。Ref: DDE-144
Summary by Sourcery
Ensure
firstNItemshonors empty-result semantics for non-positive item counts.Bug Fixes:
ItemsPage::firstNItemswhen the requested count is zero or negative, while preserving positive-count behavior.Chores: