mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-09 15:55:01 -04:00
Accounted for compact endings in expandIpv6
When an address ended in '::' the function would return an invalid string, this commit fixes that issue.
This commit is contained in:
parent
444065c926
commit
ea8acc6035
1 changed files with 5 additions and 6 deletions
|
@ -397,14 +397,9 @@ export function strToIpv6(ipStr, retArr=true) {
|
||||||
*/
|
*/
|
||||||
export function expandIpv6(ipStr) {
|
export function expandIpv6(ipStr) {
|
||||||
const compactIndex = ipStr.search("::");
|
const compactIndex = ipStr.search("::");
|
||||||
if (compactIndex === -1) {
|
|
||||||
// There were no occurances of '::'
|
|
||||||
// in ipStr.
|
|
||||||
return ipStr;
|
|
||||||
}
|
|
||||||
let expandedStr = ipStr.substring(0, compactIndex); // 1234:5678::..
|
let expandedStr = ipStr.substring(0, compactIndex); // 1234:5678::..
|
||||||
const insertOffset = compactIndex == 0;
|
const insertOffset = compactIndex == 0;
|
||||||
const ipEnd = ipStr.substring(compactIndex + 1);
|
const ipEnd = ipStr.substring(compactIndex + 1); // :7ABC:DEFG:...
|
||||||
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++) {
|
||||||
if (i % 5 == 0) {
|
if (i % 5 == 0) {
|
||||||
|
@ -413,6 +408,10 @@ export function strToIpv6(ipStr, retArr=true) {
|
||||||
}
|
}
|
||||||
expandedStr += "0";
|
expandedStr += "0";
|
||||||
}
|
}
|
||||||
|
if (compactIndex === ipStr.length - 2) {
|
||||||
|
expandedStr = expandedStr + "0";
|
||||||
|
return expandedStr;
|
||||||
|
}
|
||||||
expandedStr += ipEnd;
|
expandedStr += ipEnd;
|
||||||
return expandedStr;
|
return expandedStr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue