Improved ParseIPv6Address formatting
This commit is contained in:
parent
7af7b4df5e
commit
444065c926
@ -403,7 +403,7 @@ export function strToIpv6(ipStr, retArr=true) {
|
|||||||
return ipStr;
|
return ipStr;
|
||||||
}
|
}
|
||||||
let expandedStr = ipStr.substring(0, compactIndex); // 1234:5678::..
|
let expandedStr = ipStr.substring(0, compactIndex); // 1234:5678::..
|
||||||
const insertOffset = compactIndex == 0 ? 1 : 0;
|
const insertOffset = compactIndex == 0;
|
||||||
const ipEnd = ipStr.substring(compactIndex + 1);
|
const ipEnd = ipStr.substring(compactIndex + 1);
|
||||||
const missingChars = 39 - (expandedStr.length + ipEnd.length);
|
const missingChars = 39 - (expandedStr.length + ipEnd.length);
|
||||||
for (let i = insertOffset; i < missingChars + insertOffset; i++) {
|
for (let i = insertOffset; i < missingChars + insertOffset; i++) {
|
||||||
|
|||||||
@ -38,8 +38,9 @@ class ParseIPv6Address extends Operation {
|
|||||||
run(input, args) {
|
run(input, args) {
|
||||||
let match,
|
let match,
|
||||||
output = "";
|
output = "";
|
||||||
|
if (!(match = IPV6_REGEX.exec(input))) {
|
||||||
if ((match = IPV6_REGEX.exec(input))) {
|
throw new OperationError("Invalid IPv6 address.");
|
||||||
|
}
|
||||||
const ipv6 = strToIpv6(match[1]),
|
const ipv6 = strToIpv6(match[1]),
|
||||||
longhand = ipv6ToStr(ipv6),
|
longhand = ipv6ToStr(ipv6),
|
||||||
shorthand = ipv6ToStr(ipv6, true);
|
shorthand = ipv6ToStr(ipv6, true);
|
||||||
@ -265,9 +266,6 @@ class ParseIPv6Address extends Operation {
|
|||||||
output += "\nInterface identifier: " + intIdent +
|
output += "\nInterface identifier: " + intIdent +
|
||||||
"\nMAC address: " + mac;
|
"\nMAC address: " + mac;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
throw new OperationError("Invalid IPv6 address");
|
|
||||||
}
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user