Skip to content

Commit 51ff331

Browse files
committed
fix: Duplicate IP addresses do not prompt error messages
Add duplicate IP validation and improved error messages for IPv4/IPv6 config  - Implement duplicate IP address detection in manual configuration for both IPv4 and IPv6 - Add specific error messages for different validation failures (invalid IP, netmask, gateway, duplicates) - Introduce errorMsg property to store localized error descriptions - Update alertText to show context-specific error messages - Maintain existing validation checks while enhancing error reporting pms: BUG-312367
1 parent b094b74 commit 51ff331

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

dcc-network/qml/SectionIPv4.qml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ DccObject {
2020
property bool isEdit: false
2121
property string method: "auto"
2222

23-
property string errorKey: ""
23+
property string errorKey: ""
24+
property string errorMsg: ""
2425
signal editClicked
2526

2627
function setConfig(c) {
@@ -53,21 +54,36 @@ DccObject {
5354
}
5455
function checkInput() {
5556
errorKey = ""
57+
errorMsg = ""
5658
if (method === "manual") {
5759
for (let k in addressData) {
5860
if (!NetUtils.ipRegExp.test(addressData[k][0])) {
5961
errorKey = k + "address"
62+
errorMsg = qsTr("Invalid IP address")
6063
return false
6164
}
6265
if (!NetUtils.maskRegExp.test(addressData[k][1])) {
6366
errorKey = k + "prefix"
67+
errorMsg = qsTr("Invalid netmask")
6468
return false
6569
}
6670
if (addressData[k][2].length !== 0 && !NetUtils.ipRegExp.test(addressData[k][2])) {
6771
errorKey = k + "gateway"
72+
errorMsg = qsTr("Invalid gateway")
6873
return false
6974
}
7075
}
76+
let ipSet = new Set()
77+
for (let k in addressData) {
78+
if (!addressData[k] || !addressData[k][0]) continue;
79+
let ip = addressData[k][0]
80+
if (ipSet.has(ip)) {
81+
errorKey = k + "address"
82+
errorMsg = qsTr("Duplicate IP address")
83+
return false
84+
}
85+
ipSet.add(ip)
86+
}
7187
}
7288
return true
7389
}
@@ -288,7 +304,7 @@ DccObject {
288304
}
289305
showAlert: errorKey === index + dccObj.name
290306
alertDuration: 2000
291-
alertText: qsTr("Invalid IP address")
307+
alertText: errorKey === index + dccObj.name ? root.errorMsg : ""
292308
onShowAlertChanged: {
293309
if (showAlert) {
294310
DccApp.showPage(dccObj)

dcc-network/qml/SectionIPv6.qml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ DccObject {
2222
property string gateway: ""
2323

2424
property string errorKey: ""
25+
property string errorMsg: ""
2526
signal editClicked
2627

2728
function setConfig(c) {
@@ -47,18 +48,30 @@ DccObject {
4748
}
4849
function checkInput() {
4950
errorKey = ""
51+
errorMsg = ""
5052
if (method === "manual") {
53+
let ipSet = new Set()
5154
for (let k in addressData) {
5255
if (!NetUtils.ipv6RegExp.test(addressData[k].address)) {
5356
errorKey = k + "address"
57+
errorMsg = qsTr("Invalid IP address")
5458
return false
5559
}
5660
if (addressData[k].prefix < 0 || addressData[k].prefix > 128) {
5761
errorKey = k + "prefix"
62+
errorMsg = qsTr("Invalid netmask")
5863
return false
5964
}
65+
let ip = addressData[k].address
66+
if (ipSet.has(ip) && ip !== "") {
67+
errorKey = k + "address"
68+
errorMsg = qsTr("Duplicate IP address")
69+
return false
70+
}
71+
// 检查网关
6072
if (k === "0" && gateway.length !== 0 && !NetUtils.ipv6RegExp.test(gateway)) {
6173
errorKey = k + "gateway"
74+
errorMsg = qsTr("Invalid gateway")
6275
return false
6376
}
6477
}
@@ -292,7 +305,7 @@ DccObject {
292305
}
293306
showAlert: errorKey === index + dccObj.name
294307
alertDuration: 2000
295-
alertText: qsTr("Invalid IP address")
308+
alertText: errorKey === index + dccObj.name ? root.errorMsg : ""
296309
onShowAlertChanged: {
297310
if (showAlert) {
298311
DccApp.showPage(dccObj)
@@ -324,6 +337,7 @@ DccObject {
324337
}
325338
showAlert: errorKey === index + dccObj.name
326339
alertDuration: 2000
340+
alertText: errorKey === index + dccObj.name ? root.errorMsg : ""
327341
onShowAlertChanged: {
328342
if (showAlert) {
329343
DccApp.showPage(dccObj)
@@ -355,7 +369,7 @@ DccObject {
355369
}
356370
showAlert: errorKey === index + dccObj.name
357371
alertDuration: 2000
358-
alertText: qsTr("Invalid IP address")
372+
alertText: errorKey === index + dccObj.name ? root.errorMsg : ""
359373
onShowAlertChanged: {
360374
if (showAlert) {
361375
DccApp.showPage(dccObj)

0 commit comments

Comments
 (0)