Skip to content

Commit

Permalink
fix: IPv6 regular expression error
Browse files Browse the repository at this point in the history
IPv6 regular expression error

pms: BUG-286743
  • Loading branch information
caixr23 committed Dec 30, 2024
1 parent f81d8d8 commit 8d07809
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions dcc-network/qml/NetUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const VpnTypeEnum = Object.freeze({
"sstp": 0x40
})
// ip正则表达式
const ipRegExp = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
const ipv6RegExp = /^((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(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3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))))$/
// 子网掩码
const maskRegExp = /(254|252|248|240|224|192|128|0)\.0\.0\.0|255\.(254|252|248|240|224|192|128|0)\.0\.0|255\.255\.(254|252|248|240|224|192|128|0)\.0|255\.255\.255\.(254|252|248|240|224|192|128|0)/
// MAC正则表达式
Expand Down
6 changes: 4 additions & 2 deletions dcc-network/qml/PageDetails.qml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ DccObject {
D.IconLabel {
property bool clipboard: false
Layout.alignment: Qt.AlignRight
icon.name: "editcopy"
ToolTip {
icon.name: "dcc_network_edit"
icon.palette: D.DTK.makeIconPalette(parent.palette)
D.ToolTip {
id: tip
palette: parent.palette
}
MouseArea {
anchors.fill: parent
Expand Down
20 changes: 12 additions & 8 deletions dcc-network/qml/SectionIPv6.qml
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,18 @@ DccObject {
displayName: qsTr("IP Address")
pageType: DccObject.Editor
page: D.LineEdit {
text: addressData.length > index ? addressData[index].address : ""
text: root.addressData.length > index ? root.addressData[index].address : ""
validator: RegularExpressionValidator {
regularExpression: NetUtils.ipv6RegExp
}
onTextChanged: {
if (showAlert) {
errorKey = ""
}
if (addressData.length > index && addressData[index].address !== text) {
addressData[index].address = text
if (root.addressData.length > index && root.addressData[index].address !== text) {
var addr = root.addressData[index]
addr.address = text
root.addressData[index] = addr
root.editClicked()
}
}
Expand All @@ -305,15 +307,17 @@ DccObject {
displayName: qsTr("Prefix")
pageType: DccObject.Editor
page: D.SpinBox {
value: addressData.length > index ? addressData[index].prefix : 64
value: root.addressData.length > index ? root.addressData[index].prefix : 64
from: 0
to: 128
onValueChanged: {
if (showAlert) {
errorKey = ""
}
if (addressData.length > index && addressData[index].prefix !== value) {
addressData[index].prefix = value
if (root.addressData.length > index && root.addressData[index].prefix !== value) {
var addr = root.addressData[index]
addr.prefix = value
root.addressData[index] = addr
root.editClicked()
}
}
Expand Down Expand Up @@ -376,10 +380,10 @@ DccObject {
}

onAddressDataChanged: {
while (addressData.length > ipItems.length) {
while (root.addressData.length > ipItems.length) {
addIpItem()
}
while (addressData.length < ipItems.length) {
while (root.addressData.length < ipItems.length) {
removeIpItem()
}
}
Expand Down
Binary file added dcc-network/qml/dcc_network_edit.dci
Binary file not shown.

0 comments on commit 8d07809

Please sign in to comment.