From 31862cca18eb6007da95ee50cca2283d293ff357 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Tue, 16 Sep 2014 19:08:52 +0900 Subject: [PATCH] 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. --- common/src/main/java/io/netty/util/NetUtil.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/src/main/java/io/netty/util/NetUtil.java b/common/src/main/java/io/netty/util/NetUtil.java index 307c5a3196..295aa0d2d7 100644 --- a/common/src/main/java/io/netty/util/NetUtil.java +++ b/common/src/main/java/io/netty/util/NetUtil.java @@ -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 hexStrings = new ArrayList(); ArrayList decStrings = new ArrayList();