Skip to content

fix: set textFormat to PlainText for notification title - #1749

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
robertkill:agent/pms-bug-bot/286c9fdd80e1
Sep 22, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
robertkill:agent/pms-bug-bot/286c9fdd80e1

Conversation

@robertkill

@robertkill robertkill commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

The notification title Text element in NotifyItemContent.qml did not set textFormat, so Qt defaulted to Text.AutoText mode, which automatically detects and renders HTML tags. When a notification summary contains HTML <a> tags, the title was rendered as a blue underlined link instead of plain text.

Key evidence:

  • NotifyItemContent.qml:262 — title Text element has no textFormat set
  • NotifyItemContent.qml:284-307 — body Text element deliberately supports links (linkColor, onLinkActivated, HoverHandler), confirming the title's lack of textFormat is an omission

Fix

Add textFormat: Text.PlainText to the title Text element in NotifyItemContent.qml, ensuring the title is always rendered as plain text without HTML parsing.

Change Safety Assessment

Code Safety: Low risk. Only one QML property added (textFormat: Text.PlainText), no existing logic modified, no function signatures changed, no new dependencies introduced.

Business Impact: Notification titles (in banners and notification center) will no longer render HTML tags as link styles — they will display as plain text. Notification body text still supports links as designed. All notification views (Bubble, NormalNotify, OverlapNotify) share the NotifyItemContent component, so this one-line fix covers all scenarios.

Regression Testing: Send a notification with notify-send '<a href="https://example.com">test</a> title' "body" and verify the title displays as plain text without blue/underline styling.


根因分析

通知标题 Text 元素未设置 textFormat,Qt 默认使用 Text.AutoText 模式,自动检测并渲染 HTML 标记。当通知标题包含 HTML <a> 标签时,标题被渲染为蓝色下划线链接样式,而非纯文本。

关键证据:

  • NotifyItemContent.qml:262 — 标题 Text 元素未设置 textFormat
  • NotifyItemContent.qml:284-307 — 正文 Text 元素刻意支持链接(linkColor、onLinkActivated、HoverHandler),佐证标题缺少 textFormat 是遗漏

修复方案

在 NotifyItemContent.qml 的标题 Text 元素中添加 textFormat: Text.PlainText,使标题始终以纯文本形式渲染,不解析 HTML 标记。

改动安全评估

代码安全:低风险。仅新增一个 QML 属性(textFormat: Text.PlainText),不修改任何已有逻辑,不改变函数签名,不引入新依赖。

业务影响范围:通知标题(横幅和通知中心)将不再将 HTML 标记渲染为链接样式,改为纯文本展示。通知正文仍保留链接支持。所有通知视图(Bubble、NormalNotify、OverlapNotify)共用 NotifyItemContent 组件,一处修复覆盖全部场景。

验证建议:使用 notify-send '<a href="https://example.com">test</a> title' "body" 发送通知,验证标题以纯文本展示,无蓝色/下划线样式。

Summary by Sourcery

Bug Fixes:

  • Render notification titles as plain text so HTML markup is not interpreted as link styling.

@sourcery-ai

sourcery-ai Bot commented Sep 20, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a single QML property to prevent HTML-like notification titles from being rendered as styled links, while preserving link support in notification bodies and covering all views that reuse NotifyItemContent.

File-Level Changes

Change Details Files
Force notification titles to render as literal plain text rather than auto-detected HTML.
  • Set the title Text element's format to Text.PlainText.
  • Leave body text link handling and existing notification layout logic unchanged.
panels/notification/plugin/NotifyItemContent.qml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@18202781743

Copy link
Copy Markdown
Contributor

这pr里不应该有两个提交,

The notification title Text element in NotifyItemContent.qml did not
set textFormat, so Qt defaulted to Text.AutoText which detects and
renders HTML tags. When a notification summary contains HTML <a> tags,
the title was rendered as a blue underlined link instead of plain text.

Add textFormat: Text.PlainText to the title Text to ensure the title
is always rendered as plain text, preventing HTML tag rendering.

Log: fix notification title showing link style with HTML tags
Bug: https://pms.uniontech.com/bug-view-377829.html
Change-Id: IF3B5F7F293B005B5
@robertkill
robertkill force-pushed the agent/pms-bug-bot/286c9fdd80e1 branch from 0e50b87 to 3ef3361 Compare September 22, 2026 07:21
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, robertkill

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@18202781743

Copy link
Copy Markdown
Contributor

/forcemerege

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 98 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 98 分,大于 70 分通过阈值,代码质量符合要求。本次变更仅新增一行 QML 属性 textFormat: Text.PlainText,修复了通知标题未设置文本格式导致 HTML 标记被渲染为链接样式的问题,变更安全且有效。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 语法正确,无需修改。textFormat: Text.PlainText 是有效的 QML 属性赋值,正确放置在 Text 元素的属性块中(第262-278行),与现有属性 text、visible、maximumLineCount、font、color、renderType、wrapMode、elide 等并列。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 建议在 textFormat: Text.PlainText 上方添加简短注释,例如 // 使用 PlainText 防止标题中的 HTML 标记被渲染为链接样式,与 body Text 元素的注释风格保持一致,提高可维护性。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 性能良好。设置 textFormat 为 Text.PlainText 实际上提升了性能,因为 Qt 不再需要执行 AutoText 模式的 HTML 自动检测和解析,直接以纯文本模式渲染,减少了不必要的处理开销。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 本次变更提升了安全性。通过将标题文本格式限制为 PlainText,防止了通知标题中潜在的 HTML 标记注入风险(如 标签、 标签等),避免了类似 XSS 的渲染问题。通知正文(body Text)仍保留 RichText 支持并有 linkActivated 处理,设计合理。


💡 改进建议代码示例

// 标题 Text 元素:使用 PlainText 防止 HTML 标记渲染
Text {
    text: root.title
    visible: text !== ""
    maximumLineCount: 1
    textFormat: Text.PlainText  // 确保标题始终以纯文本形式渲染
    font {
        pixelSize: DTK.fontManager.t8.pixelSize
        family: DTK.fontManager.t8.family
        bold: true
    }
    color: palette.windowText
    renderType: Text.QtRendering
    wrapMode: Text.NoWrap
    elide: Text.ElideRight
    Layout.fillWidth: true
    Layout.alignment: Qt.AlignLeft | Qt.AlignTop
}

本报告由 AI 代码审查工具自动生成

@18202781743

Copy link
Copy Markdown
Contributor

/forcemerge

@deepin-bot

deepin-bot Bot commented Sep 22, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit e4134a9 into linuxdeepin:master Sep 22, 2026
5 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants