refactor(ip-parsing): centralize multi-delim splitting in splitIps

Extend splitIps to accept comma/semicolon/newline delimiters with dedupe,
and reuse it in DetailPanel for both the IP list and the service-URL host.
Fixes ServiceBadge links pointing at concatenated string when IPs were
entered with ';' or newline separators. Adds tests for new delimiters.
This commit is contained in:
Pouzor
2026-05-15 13:36:15 +02:00
parent 9cd93ef294
commit ea451885af
4 changed files with 43 additions and 13 deletions
+5 -4
View File
@@ -25,16 +25,17 @@ function maskSingle(ip: string): string {
*/
export function maskIp(ip: string): string {
if (!ip) return ip
return ip.split(',').map(maskSingle).join(', ')
return splitIps(ip).map(maskSingle).join(', ')
}
/**
* Split a comma-separated IP string into an array of trimmed values.
* Empty string returns [].
* Split an IP string into trimmed values. Accepts comma, semicolon, or newline
* delimiters (or any combination). Duplicates removed, empty entries dropped.
*/
export function splitIps(ip: string): string[] {
if (!ip?.trim()) return []
return ip.split(',').map((s) => s.trim()).filter(Boolean)
const parts = ip.split(/[\n,;]+/).map((s) => s.trim()).filter(Boolean)
return parts.filter((v, i) => parts.indexOf(v) === i)
}
/**