Skip to content

fix: use nm_utils_ssid_to_utf8 for SSID decoding in AccessPoint - #7

Open
caixr23 wants to merge 1 commit into
deepin-community:masterfrom
caixr23:fix/ssid-gbk-decode
Open

caixr23 wants to merge 1 commit into
deepin-community:masterfrom
caixr23:fix/ssid-gbk-decode

Conversation

@caixr23

@caixr23 caixr23 commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

The SSID decoding in AccessPointPrivate::propertiesChanged() was hardcoded to QString::fromUtf8(rawSsid). For SSIDs encoded with GBK/GB2312 (common in Chinese network environments), this produced garbled text in the network list. The rawSsid (QByteArray) was stored correctly, but the ssid (QString) used for display was incorrectly decoded.

Key evidence:

  • accesspoint.cpp line 199 (before fix): ssid = QString::fromUtf8(rawSsid) — hardcoded UTF-8, no fallback
  • Only AccessPoint::ssid() (returns QString) was affected; WirelessSetting::ssid() (returns QByteArray) was not
  • The deepin fork networkmanager-qt6 had no modifications to this code — identical to upstream KDE

Fix

Replace the hardcoded QString::fromUtf8(rawSsid) with nm_utils_ssid_to_utf8() from libnm, consistent with how nmtui decodes SSIDs:

  1. Add #include <libnm/NetworkManager.h> to accesspoint.cpp
  2. Call nm_utils_ssid_to_utf8() to decode the raw SSID bytes to a UTF-8 string
  3. Convert the C string to QString via QString::fromUtf8() and free with g_free()

nm_utils_ssid_to_utf8() handles encoding detection:

  • Validates UTF-8 and returns directly if valid
  • Falls back to locale-aware encoding detection (including GBK/GB2312 for zh_CN locale)
  • Falls back to ISO-8859-1 as last resort

This is complementary to dde-network-core PR #627, which handles the display and save paths at the DDE layer. Both fixes can be merged independently.

Safety Assessment

  • Risk level: Low
  • UTF-8 encoded SSIDs are decoded correctly (nm_utils_ssid_to_utf8 validates UTF-8 first)
  • Non-UTF-8 SSIDs are decoded using the same function as nmtui, ensuring consistent behavior
  • No new dependencies — libnm is already a REQUIRED PUBLIC dependency of networkmanager-qt6
  • rawSsid() and other APIs are completely unaffected

Test Suggestion

  • Verify UTF-8 encoded SSID networks still display correctly (no regression)
  • Verify GBK encoded SSID networks now display correctly instead of garbled text
  • Verify ssidChanged signal carries correct value for both encodings

根因分析

AccessPointPrivate::propertiesChanged() 中 SSID 解码硬编码为 QString::fromUtf8(rawSsid),对 GBK/GB2312 编码的 SSID 产生乱码。

修复方案

使用 libnm 的 nm_utils_ssid_to_utf8() 替换硬编码的 fromUtf8,与 nmtui 的 SSID 解码方式保持一致。nm_utils_ssid_to_utf8() 会先验证 UTF-8,失败时根据 locale 回退到对应编码(如 zh_CN 下尝试 GBK/GB2312),最后回退 ISO-8859-1。

libnm 已是 networkmanager-qt6 的 REQUIRED PUBLIC 依赖,无需新增依赖。

与 dde-network-core PR #627 互补,两者可分别合入。

安全评估

  • 风险等级:低
  • UTF-8 编码 SSID 走相同的验证路径(零行为变更)
  • 非 UTF-8 SSID 使用与 nmtui 相同的解码逻辑
  • libnm 已是现有依赖,无新增依赖

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign liujianqiang-niu for approval. For more information see the Code Review Process.

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

@deepin-ci-robot

Copy link
Copy Markdown

Hi @caixr23. Thanks for your PR.

I'm waiting for a deepin-community member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

The SSID decoding in AccessPointPrivate::propertiesChanged() was
hardcoded to QString::fromUtf8(), which produced garbled text for
SSIDs encoded with GBK/GB2312 (common in Chinese network environments).

Replace the hardcoded fromUtf8 with nm_utils_ssid_to_utf8() from
libnm, consistent with how nmtui decodes SSIDs. This function:
1. Validates UTF-8 and returns directly if valid
2. Falls back to locale-aware encoding detection (including GBK/GB2312
   when locale is zh_CN) for non-UTF-8 SSIDs
3. Falls back to ISO-8859-1 as last resort

This fixes the root cause at the source: AccessPoint::ssid() now
returns correctly decoded text, and the ssidChanged signal carries
the correct value. This complements the dde-network-core PR #627
which handles the display/save paths at the DDE layer.

PMS: BUG-357843
@caixr23
caixr23 force-pushed the fix/ssid-gbk-decode branch from 1161a15 to 2907e53 Compare September 17, 2026 06:21
@caixr23 caixr23 changed the title fix: add GBK fallback for SSID decoding in AccessPoint fix: use nm_utils_ssid_to_utf8 for SSID decoding in AccessPoint Sep 17, 2026
@mhduiy

mhduiy commented Sep 21, 2026

Copy link
Copy Markdown

问题不复现,中间版本已经修复了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants