Skip to content

fix: remove MAC address validator from cloned MAC field#507

Merged
robertkill merged 1 commit intolinuxdeepin:masterfrom
robertkill:master
Feb 27, 2026
Merged

fix: remove MAC address validator from cloned MAC field#507
robertkill merged 1 commit intolinuxdeepin:masterfrom
robertkill:master

Conversation

@robertkill
Copy link
Contributor

  1. Removed the RegularExpressionValidator that enforced MAC address format validation on the cloned-mac-address field
  2. This change allows users to input any text value in the cloned MAC address field without format restrictions
  3. The validator was likely too restrictive for certain use cases where non-standard MAC address formats might be needed
  4. The field still retains its basic functionality but without the format validation constraint

Influence:

  1. Test entering various text values in the cloned MAC address field including valid MAC addresses, invalid formats, and arbitrary text
  2. Verify that all input values are accepted without validation errors
  3. Ensure the application doesn't crash when saving non-standard MAC address values
  4. Test that the cloned MAC address functionality still works correctly with valid MAC addresses
  5. Verify that the UI properly displays whatever value is entered in the field

fix: 从克隆MAC地址字段移除MAC地址验证器

  1. 移除了对克隆MAC地址字段强制实施MAC地址格式验证的 RegularExpressionValidator
  2. 此更改允许用户在克隆MAC地址字段中输入任何文本值,不受格式限制
  3. 验证器可能对某些需要非标准MAC地址格式的使用场景过于严格
  4. 该字段仍保留其基本功能,但不再有格式验证约束

Influence:

  1. 测试在克隆MAC地址字段中输入各种文本值,包括有效的MAC地址、无效格式和 任意文本
  2. 验证所有输入值都能被接受,不会出现验证错误
  3. 确保应用程序在保存非标准MAC地址值时不会崩溃
  4. 测试克隆MAC地址功能在使用有效MAC地址时仍能正常工作
  5. 验证UI能正确显示输入到字段中的任何值

PMS: BUG-351321

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.

Sorry @robertkill, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

1. Removed the RegularExpressionValidator that enforced MAC address
format validation on the cloned-mac-address field
2. This change allows users to input any text value in the cloned MAC
address field without format restrictions
3. The validator was likely too restrictive for certain use cases where
non-standard MAC address formats might be needed
4. The field still retains its basic functionality but without the
format validation constraint

Influence:
1. Test entering various text values in the cloned MAC address field
including valid MAC addresses, invalid formats, and arbitrary text
2. Verify that all input values are accepted without validation errors
3. Ensure the application doesn't crash when saving non-standard MAC
address values
4. Test that the cloned MAC address functionality still works correctly
with valid MAC addresses
5. Verify that the UI properly displays whatever value is entered in
the field

fix: 从克隆MAC地址字段移除MAC地址验证器

1. 移除了对克隆MAC地址字段强制实施MAC地址格式验证的
RegularExpressionValidator
2. 此更改允许用户在克隆MAC地址字段中输入任何文本值,不受格式限制
3. 验证器可能对某些需要非标准MAC地址格式的使用场景过于严格
4. 该字段仍保留其基本功能,但不再有格式验证约束

Influence:
1. 测试在克隆MAC地址字段中输入各种文本值,包括有效的MAC地址、无效格式和
任意文本
2. 验证所有输入值都能被接受,不会出现验证错误
3. 确保应用程序在保存非标准MAC地址值时不会崩溃
4. 测试克隆MAC地址功能在使用有效MAC地址时仍能正常工作
5. 验证UI能正确显示输入到字段中的任何值

PMS: BUG-351321
@deepin-ci-robot
Copy link

deepin pr auto review

针对,我将从多个角度对这段代码的变更进行审查:

1. 语法逻辑分析

变更内容:

  • 删除了 RegularExpressionValidator,该验证器用于验证 MAC 地址格式
  • 修改了版权年份范围(2024-2027 → 2024-2026)

逻辑问题:

  • 删除 MAC 地址验证器后,用户可以输入任意格式的文本作为克隆 MAC 地址
  • 这可能导致无效的 MAC 地址被保存到配置中

2. 代码质量评估

改进建议:

  1. 验证逻辑缺失:删除验证器后,应确保在 onTextChanged 中添加格式验证逻辑
  2. 错误处理不足:当前代码仅在 showAlert 为真时清空错误,但没有验证输入的有效性
  3. 用户体验下降:实时验证可以防止用户输入无效格式

3. 代码性能考虑

  • 删除验证器实际上减少了运行时验证开销,但这不是正确的优化方向
  • 建议保留验证器或实现更高效的验证方式

4. 代码安全风险

严重问题:

  1. 输入验证缺失:允许任意输入可能导致:

    • 无效的 MAC 地址被写入系统配置
    • 潜在的系统配置错误
    • 网络功能异常
  2. 数据完整性风险:没有验证的输入可能破坏网络配置

改进建议方案

DccTitleObject {
    // ... 其他代码 ...
    
    DccObject {
        name: "cloned-mac-address"
        displayName: qsTr("Cloned MAC Address")
        pageType: DccObject.Editor
        page: D.LineEdit {
            text: root.config.hasOwnProperty("cloned-mac-address") ? root.config["cloned-mac-address"] : ""
            
            // 保留验证器或实现自定义验证
            validator: RegularExpressionValidator {
                regularExpression: NetUtils.macRegExp
            }
            
            // 添加输入验证逻辑
            onTextChanged: {
                // 清除错误状态
                if (showAlert) {
                    errorKey = ""
                }
                
                // 验证输入有效性
                const isValid = NetUtils.macRegExp.test(text)
                if (!isValid && text !== "") {
                    errorKey = "invalid-mac-address"
                    // 可以添加视觉反馈
                    errorHighlight = true
                } else {
                    errorHighlight = false
                }
            }
            
            // 添加提交前验证
            onEditingFinished: {
                if (text !== "" && !NetUtils.macRegExp.test(text)) {
                    // 显示错误提示
                    errorKey = "invalid-mac-address"
                }
            }
        }
    }
}

额外建议

  1. 错误处理增强

    • 添加明确的错误消息显示
    • 考虑添加输入提示(placeholder)
  2. 验证策略

    • 保留 RegularExpressionValidator 用于实时验证
    • 添加提交前的最终验证
    • 考虑添加输入格式提示(如 "XX:XX:XX:XX:XX:XX")
  3. 用户体验改进

    • 添加输入格式说明
    • 提供示例 MAC 地址
    • 考虑添加"生成随机 MAC"功能
  4. 测试建议

    • 测试各种边界情况(空输入、部分输入、无效格式)
    • 验证错误处理流程
    • 确保保存前验证
  5. 文档更新

    • 如果删除验证器是故意的,应在代码注释中说明原因
    • 更新相关文档说明输入格式要求

结论

不建议删除 MAC 地址验证器,这会引入严重的安全和功能问题。如果确实需要修改验证方式,应该:

  1. 提供替代的验证机制
  2. 确保输入验证的完整性
  3. 添加适当的错误处理和用户反馈
  4. 充分测试各种输入场景

建议撤销此变更,或采用上述改进方案来实现更完善的输入验证机制。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: caixr23, 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

@robertkill robertkill merged commit 6d87877 into linuxdeepin:master Feb 27, 2026
16 of 18 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