Skip to content

Conversation

@wyu71
Copy link
Contributor

@wyu71 wyu71 commented Dec 8, 2025

  • Added unescaping for single and double quotes in notification body text.

Log: resolve notification display issue for Bluetooth device names with quotes
pms: BUG-342911

Summary by Sourcery

Bug Fixes:

  • Correct notification body rendering by converting escaped single and double quotes (e.g., " and ") back to literal quote characters.

@sourcery-ai
Copy link

sourcery-ai bot commented Dec 8, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds unescaping of single and double quote escape sequences in notification body text to correctly display Bluetooth device names containing quotes.

File-Level Changes

Change Details Files
Normalize notification body text by unescaping backslash-escaped quotes after existing backslash normalization.
  • Keep existing replacement that converts double backslashes to single backslashes in the notification body text.
  • Add replacement to convert escaped double quotes (") to literal double quote characters in the notification body.
  • Add replacement to convert escaped single quotes (') to literal single quote characters in the notification body.
panels/notification/server/notificationmanager.cpp

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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Consider clarifying in a comment or helper function that the order of replacements (backslashes first, then quotes) is intentional and safe, since inputs like \\" will now collapse to " and may not always reflect the original intent.
  • If this unescaping is specific to %q-formatted Bluetooth names, it might be safer to gate it behind a more targeted condition or helper function so that other callers of Notify with legitimate backslash-escaped content are not unintentionally altered.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider clarifying in a comment or helper function that the order of replacements (backslashes first, then quotes) is intentional and safe, since inputs like `\\"` will now collapse to `"` and may not always reflect the original intent.
- If this unescaping is specific to %q-formatted Bluetooth names, it might be safer to gate it behind a more targeted condition or helper function so that other callers of `Notify` with legitimate backslash-escaped content are not unintentionally altered.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

- Added unescaping for single and double quotes in notification body text.

Log: resolve notification display issue for Bluetooth device names with quotes
pms: BUG-342911
@deepin-ci-robot
Copy link

deepin pr auto review

我来帮你分析这段代码的改进意见:

  1. 代码逻辑改进:
    原代码使用简单的字符串替换:
strBody.replace(QLatin1String("\\\\"), QLatin1String("\\"), Qt::CaseInsensitive);

新代码使用正则表达式:

strBody.replace(QRegularExpression("\\\\(\\\\|['\"])"), "\\1");

这个改进是合理的,因为:

  • 原代码只处理了双反斜杠的情况,可能遗漏其他转义字符
  • 新代码通过正则表达式统一处理了反斜杠、单引号和双引号的转义
  • 添加了清晰的注释说明代码目的
  1. 性能考虑:
  • 正则表达式虽然功能强大,但比简单的字符串替换稍慢
  • 如果通知消息频繁且内容很长,可能需要考虑性能影响
  • 建议可以缓存 QRegularExpression 对象以提高性能
  1. 安全性改进:
  • 建议添加输入验证,确保 strBody 不为空
  • 可以考虑限制输入字符串长度,防止潜在的 DoS 攻击
  • 应该处理正则表达式匹配失败的情况
  1. 代码质量建议:
// 建议的改进版本
static const QRegularExpression escapePattern("\\\\(\\\\|['\"])");

uint NotificationManager::Notify(const QString &appName, uint replacesId, const QString &appIcon, 
                               const QString &summary, const QString &body, ...)
{
    if (body.isEmpty()) {
        qWarning() << "Empty notification body received";
        return 0;
    }
    
    QString strBody = body;
    // Unescape backslashes and quotes from %q formatted strings
    auto match = escapePattern.match(strBody);
    if (match.hasMatch()) {
        strBody.replace(escapePattern, "\\1");
    }
    
    // ... 其余代码
}

这个改进版本:

  • 使用静态正则表达式对象提高性能
  • 添加了输入验证
  • 添加了错误处理
  • 保持了原有功能的完整性
  • 代码结构更清晰
  1. 其他建议:
  • 考虑添加单元测试来验证各种转义字符的处理
  • 添加日志记录,便于调试和问题追踪
  • 考虑将字符串处理逻辑抽取为独立函数,提高代码复用性

总的来说,这个改动是正向的,主要改进了字符串处理的完整性,但还可以在性能和安全性方面做进一步优化。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@wyu71
Copy link
Contributor Author

wyu71 commented Dec 9, 2025

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Dec 9, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 98ea2e7 into linuxdeepin:master Dec 9, 2025
10 of 11 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