Fix a bug in NetUtil.createByteArrayFromIpAddressString()

Motivation:

An IPv6 string can have a zone index which is followed by the '%' sign.
When a user passes an IPv6 string with a zone index,
NetUtil.createByteArrayFromIpAddressString() returns an incorrect value.

Modification:

- Strip the zone index before conversion

Result:

An IPv6 string with a zone index is decoded correctly.
This commit is contained in:
Trustin Lee 2014-09-16 19:08:52 +09:00
parent fe05b6e514
commit 9839990fff

View File

@ -238,6 +238,11 @@ public final class NetUtil {
ipAddressString = ipAddressString.substring(1, ipAddressString.length() - 1);
}
int percentPos = ipAddressString.indexOf('%');
if (percentPos >= 0) {
ipAddressString = ipAddressString.substring(0, percentPos);
}
StringTokenizer tokenizer = new StringTokenizer(ipAddressString, ":.", true);
ArrayList<String> hexStrings = new ArrayList<String>();
ArrayList<String> decStrings = new ArrayList<String>();