File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,8 +34,27 @@ unzero(){
3434# function to remove leading zeros in IPv6 address
3535unzero6(){
3636 local A M Q
37+ if [[ $1 == "::" ]]; then
38+ printf "::"
39+ return 0
40+ fi
41+ # Replace first :: with sentinel
3742 A=${1/::/:-:}
38- echo -n $(for Q in ${A//:/ }; do [[ $Q != - ]] && printf "$M%x" "0x$Q" || printf ":"; M=:; done)
43+ M=
44+ for Q in ${A//:/ }; do
45+ if [[ $Q != - ]]; then
46+ # Validate hex (1-4 digits)
47+ [[ $Q =~ ^[0-9A-Fa-f]{1,4}$ ]] || return 1
48+ printf "%s%x" "$M" "0x$Q"
49+ else
50+ # Restore a single colon for sentinel
51+ printf ":"
52+ fi
53+ M=:
54+ done
55+
56+ # Handle trailing :: (but avoid adding for the special case "::")
57+ [[ $1 == *:: && $1 != "::" ]] && printf ":"
3958}
4059
4160# Bergware - use associative format for multi-dimensional arrays
You can’t perform that action at this time.
0 commit comments