Skip to content

Commit

Permalink
Fix #2313: Defect in j.n.InetAddress#createIPStringFromByteArray (#2348)
Browse files Browse the repository at this point in the history
* Fix createIPStringFromByteArray ignoring last group

Previously, if values in the last group were all equal to 0,
they would be ignored in the string.

* Add test for issue
  • Loading branch information
jchyb committed Aug 11, 2021
1 parent 1e776fe commit 4e0de6f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions javalib/src/main/scala/java/net/InetAddress.scala
Expand Up @@ -520,6 +520,9 @@ private[net] trait InetAddressBase {
buffer.append('0')
buffer.append(':')
}
if ((i & 1) != 0 && (i + 1) == ipByteArray.length && isFirst) {
buffer.append('0')
}
}
return buffer.toString
}
Expand Down
Expand Up @@ -113,4 +113,10 @@ class Inet6AddressTest {
Inet6Address.getByAddress("123", addr2, -1)
}

// Issue 2313
@Test def trailing0NotLost(): Unit = {
val addr = InetAddress.getByName("1c1e::")
assertTrue(addr.getHostAddress().endsWith("0"))
}

}

0 comments on commit 4e0de6f

Please sign in to comment.