diff --git a/frontend/src/utils/util.ts b/frontend/src/utils/util.ts index 7f084482e..6ad3d8bcc 100644 --- a/frontend/src/utils/util.ts +++ b/frontend/src/utils/util.ts @@ -168,6 +168,9 @@ export function checkIp(value: string): boolean { } export function checkPort(value: string): boolean { + if (Number(value) <= 0) { + return true; + } const reg = /^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$/; if (!reg.test(value) && value !== '') { return true; diff --git a/frontend/src/views/host/firewall/port/operate/index.vue b/frontend/src/views/host/firewall/port/operate/index.vue index 46368879b..bf5344f7f 100644 --- a/frontend/src/views/host/firewall/port/operate/index.vue +++ b/frontend/src/views/host/firewall/port/operate/index.vue @@ -123,9 +123,12 @@ const onSubmit = async (formEl: FormInstance | undefined) => { dialogData.value.rowData.address = ''; } let ports = []; - if (dialogData.value.rowData.port.indexOf('-') !== -1) { + if (dialogData.value.rowData.port.indexOf('-') !== -1 && !dialogData.value.rowData.port.startsWith('-')) { ports = dialogData.value.rowData.port.split('-'); - } else if (dialogData.value.rowData.port.indexOf(',') !== -1) { + } else if ( + dialogData.value.rowData.port.indexOf(',') !== -1 && + !dialogData.value.rowData.port.startsWith(',') + ) { ports = dialogData.value.rowData.port.split(','); } else { ports.push(dialogData.value.rowData.port);