fix: support GBK-encoded SSID display and match - #635
Conversation
Reviewer's GuideThe PR introduces locale-aware SSID display decoding, exposes raw SSID bytes across NM/DSS and public access-point APIs, and updates all wireless connection matching and persistence paths to use exact raw bytes with UTF-8 fallback for historical connections. Sequence diagram for raw SSID matching and connection persistencesequenceDiagram
participant User
participant AccessPoints
participant NetWirelessConnect
participant NetworkManager
participant SavedConnection
User->>AccessPoints: rawSsid()
AccessPoints-->>NetWirelessConnect: raw SSID bytes
NetWirelessConnect->>NetworkManager: availableConnections()
NetworkManager-->>NetWirelessConnect: saved wireless settings
alt raw SSID matches
NetWirelessConnect->>SavedConnection: reuse connection
else UTF-8 display name matches historical connection
NetWirelessConnect->>SavedConnection: reuse historical connection
else no match
NetWirelessConnect->>SavedConnection: setSsid(rawSsid())
NetWirelessConnect->>NetworkManager: create connection
end
Flow diagram for locale-aware SSID display decodingflowchart LR
RawSSID[Raw SSID bytes] --> UTF8{Valid UTF-8?}
UTF8 -->|Yes| Display[UTF-8 display string]
UTF8 -->|No| Locale[Locale encoding candidates]
Locale -->|Successful decode| Display
Locale -->|All fail| ASCII[Printable ASCII fallback]
ASCII --> Display
Display --> UI[Control center, dock, or QML UI]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/impl/serviceinter/accesspointsproxyinter.cpp" line_range="33-35" />
<code_context>
return m_json.value("Ssid").toString();
}
+QByteArray AccessPointsProxyInter::rawSsid() const
+{
+ // DSS 服务目前仅下发显示用的 Ssid 字符串,未提供原始字节;
+ // 若服务端未来提供 RawSsid(base64)字段,在此解析返回。
+ if (m_json.contains("RawSsid")) {
+ return QByteArray::fromBase64(m_json.value("RawSsid").toString().toLatin1());
+ }
+ if (m_json.contains("Ssid")) {
+ return QByteArray::fromBase64(m_json.value("Ssid").toString().toLatin1());
+ }
+
+ return QByteArray();
+}
</code_context>
<issue_to_address>
**issue (bug_risk):** When the DSS payload contains only the documented display-name `Ssid` field, `rawSsid()` base64-decodes that ordinary string and returns unrelated bytes instead of an empty raw SSID. DSS connections created through this wrapper are therefore saved with corrupt SSID bytes, and exact raw-byte matching fails for DSS access points.
**Triggers:** When the DSS service has not yet added a separate `RawSsid` field.
**Suggested fix:** Return an empty `QByteArray` when only `Ssid` is present; decode only a documented raw-byte field, or update the DSS service to provide `RawSsid` explicitly.
```suggestion
```
</issue_to_address>
### Comment 2
<location path="src/impl/networkmanager/accesspointproxynm.cpp" line_range="150-152" />
<code_context>
return false;
- return wirelessSetting->ssid() == tmpAp->ssid() && !connection->isUnsaved();
+ const QByteArray rawSsid = tmpAp->rawSsid();
+ // 优先按原始字节匹配(连接保存的是 AP 原始字节),其次兼容 UTF-8 显示名匹配历史连接
+ return ((!rawSsid.isEmpty() && wirelessSetting->ssid() == rawSsid)
+ || wirelessSetting->ssid() == tmpAp->ssid().toUtf8())
</code_context>
<issue_to_address>
**issue (bug_risk):** Both callers dereference `m_network->referenceAccessPoint()` directly before obtaining its SSID, even though `rawSsid()` explicitly treats a null reference access point as a valid state and returns an empty byte array. If the reference AP disappears during network refresh or teardown, `initState()` or `updateHiddenInfo()` crashes.
**Triggers:** When a wireless network temporarily has no reference access point during an update or teardown.
**Suggested fix:** Use `rawSsid()` without dereferencing the reference AP directly, or check `referenceAccessPoint()` for null before accessing it.
</issue_to_address>| if (m_json.contains("Ssid")) { | ||
| return QByteArray::fromBase64(m_json.value("Ssid").toString().toLatin1()); | ||
| } |
There was a problem hiding this comment.
issue (bug_risk): When the DSS payload contains only the documented display-name Ssid field, rawSsid() base64-decodes that ordinary string and returns unrelated bytes instead of an empty raw SSID. DSS connections created through this wrapper are therefore saved with corrupt SSID bytes, and exact raw-byte matching fails for DSS access points.
Triggers: When the DSS service has not yet added a separate RawSsid field.
Suggested fix: Return an empty QByteArray when only Ssid is present; decode only a documented raw-byte field, or update the DSS service to provide RawSsid explicitly.
| if (m_json.contains("Ssid")) { | |
| return QByteArray::fromBase64(m_json.value("Ssid").toString().toLatin1()); | |
| } |
| // 优先按原始字节匹配(连接保存的是 AP 原始字节),其次兼容 UTF-8 显示名匹配历史连接 | ||
| if (!((!rawSsid.isEmpty() && wirelessSetting->ssid() == rawSsid) | ||
| || wirelessSetting->ssid() == ssid().toUtf8())) |
There was a problem hiding this comment.
issue (bug_risk): Both callers dereference m_network->referenceAccessPoint() directly before obtaining its SSID, even though rawSsid() explicitly treats a null reference access point as a valid state and returns an empty byte array. If the reference AP disappears during network refresh or teardown, initState() or updateHiddenInfo() crashes.
Triggers: When a wireless network temporarily has no reference access point during an update or teardown.
Suggested fix: Use rawSsid() without dereferencing the reference AP directly, or check referenceAccessPoint() for null before accessing it.
1447664 to
a141b83
Compare
|
TAG Bot New tag: 2.0.102 |
223b4ac to
128b6e1
Compare
1. Add ssidToUtf8() to netutils: a locale-aware SSID byte-to-UTF-8 decoder modeled on NetworkManager's nm_utils_ssid_to_utf8 (UTF-8 validate -> language encoding table, GB18030 for zh -> system charset/iso-8859-1/windows-1251 -> printable ASCII). 2. Expose rawSsid() on AccessPointProxy (base + NM backend + DSS backend) and on the public AccessPoints wrapper so callers can obtain the AP's raw SSID bytes. 3. Use rawSsid() as the primary match key in all connect/lookup paths (devicemanagerrealize, accesspointproxynm initState / updateHiddenInfo, netmanagerthreadprivate connect / available connections / hidden / portal, netwirelessconnect) and save new connections with the raw bytes; fall back to the UTF-8 display name for historical connections. 4. Decode the hotspot SSID to UTF-8 in NetHotspotController::updateConfig so QML no longer renders a raw QByteArray as UTF-8 mojibake. Log: Wi-Fi network names with GBK-encoded SSIDs now display correctly instead of garbled, and existing connections are matched properly. Influence: 1. Create a hotspot with a GBK-encoded SSID, open the control center / dock network list and verify the name shows correctly and the connection status / has-connection indicator is right. 2. Scan a GBK-SSID AP and connect with a password: verify the password dialog appears, the connection succeeds, and a saved GBK connection is matched (shown as connected, not new). fix: 支持 GBK 编码 SSID 的显示与匹配 1. 在 netutils 新增 ssidToUtf8(),按 locale 感知将 SSID 原始字节 解码为 UTF-8,实现对齐 NetworkManager 的 nm_utils_ssid_to_utf8 (UTF-8 校验 -> 语言编码表,中文用 GB18030 -> 系统 charset/ iso-8859-1/windows-1251 -> 可打印 ASCII 兜底)。 2. 在 AccessPointProxy(基类 + NM 后端 + DSS 后端)及公开的 AccessPoints 上暴露 rawSsid(),供调用方获取 AP 的原始字节。 3. 所有连接/查找路径改用 rawSsid() 作为优先匹配键 (devicemanagerrealize、accesspointproxynm 的 initState/ updateHiddenInfo、netmanagerthreadprivate 的连接/可用连接/ 隐藏网络/门户、netwirelessconnect),新建连接保存原始字节, 历史连接回退按 UTF-8 显示名匹配。 4. NetHotspotController::updateConfig 将热点 SSID 解码为 UTF-8,避免 QML 把原始 QByteArray 按 UTF-8 直读成乱码。 Log: GBK 编码的无线网络名不再显示为乱码,已有连接也能正确匹配。 Influence: 1. 创建一个 GBK 编码 SSID 的热点,打开控制中心/dock 网络列表, 确认名称正常显示、连接状态与「已有连接」标识正确。 2. 扫描 GBK SSID 的 AP 并用密码连接:确认密码框正常弹出、连接 成功,且已保存的 GBK 连接被匹配(显示为已连接而非新网络)。 PMS: BUG-357843
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
📋 代码目的分析本 PR 修复 GBK 编码 SSID 在显示时出现乱码以及在连接匹配时失败的问题。核心实现方案:
🔍 详细分析1. 语法逻辑 ✅ (25/25分)评价: 语法正确,逻辑清晰 ✅ 潜在问题: 分析说明:
2. 代码质量 ✅ (24/25分)评价: 代码结构清晰,注释完整 ✅ 潜在问题:
分析说明:
3. 代码性能 ✅ (17/20分)评价: 算法复杂度合理 ✅ 潜在问题:
建议:
优化代码示例: QString ssidToUtf8(const QByteArray &raw)
{
if (raw.isEmpty())
return {};
// 1) 已是 UTF-8 → 直接返回
static const QStringDecoder u8Decoder(QStringDecoder::Utf8);
QStringDecoder u8(u8Decoder);
QString out = u8.decode(raw);
if (!u8.hasError())
return out;
// 2) 缓存候选编码列表(系统 locale 不变)
static const QStringList candidates = []() {
return decodeCandidates(QLocale::system());
}();
for (const QString &enc : candidates) {
QStringDecoder d(enc);
if (!d.isValid())
continue;
d.resetState();
out = d.decode(raw);
if (!d.hasError())
return out;
}
// 3) 兜底: 可打印 ASCII,其余 '?'
QString ascii;
ascii.reserve(raw.size());
for (char c : raw)
ascii += (c >= 0x20 && c <= 0x7E) ? QChar(c) : QChar('?');
return ascii;
}4. 代码安全 🔒 (30/30分)评价: 存在0个安全漏洞 ✅ 安全合规
安全漏洞详情: 安全分析:
漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个 📈 维度评分汇总
💡 改进建议汇总
本报告由 AI 代码审查工具自动生成 审查时间: 2026-09-24 08:59:00 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, caixr23, ut003640 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 |
Log: Wi-Fi network names with GBK-encoded SSIDs now display correctly instead of garbled, and existing connections are matched properly.
Influence:
fix: 支持 GBK 编码 SSID 的显示与匹配
Log: GBK 编码的无线网络名不再显示为乱码,已有连接也能正确匹配。
Influence:
PMS: BUG-357843
Summary by Sourcery
Support locale-encoded Wi-Fi SSIDs by decoding them for display and matching connections using their original bytes.
New Features:
Bug Fixes: