Skip to content

Commit

Permalink
Fix #317
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilquist committed Sep 27, 2021
1 parent 3a63b21 commit ee7a8f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions shared/src/main/scala/com/comcast/ip4s/Host.scala
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,12 @@ object Ipv6Address extends Ipv6AddressCompanionPlatform {
var beforeCondenser = true
var suffix: List[Int] = Nil
val trimmed = value.trim()
var result: Option[Ipv6Address] = null
val fields =
if (trimmed.nonEmpty) trimmed.split(":") else Array.empty[String]
if (trimmed.contains(':')) trimmed.split(':')
else Array.empty[String]
// if (trimmed.nonEmpty) trimmed.split(':') else Array.empty[String]
var idx = 0
var result: Option[Ipv6Address] = null
while (idx < fields.size && (result eq null)) {
val field = fields(idx)
if (field.isEmpty) {
Expand Down Expand Up @@ -607,7 +609,7 @@ object Ipv6Address extends Ipv6AddressCompanionPlatform {
}
if (result ne null) {
result
} else if (fields.isEmpty && (trimmed.isEmpty || trimmed == ":")) {
} else if (fields.isEmpty && (trimmed.isEmpty || trimmed != "::")) {
None
} else {
val bytes = new Array[Byte](16)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Ipv6AddressTest extends BaseTestSuite {
assertEquals(Ipv6Address.fromString(":"), None)
assertEquals(Ipv6Address.fromString(" : "), None)
}

test("parsing from string - does parse ::") {
assertEquals(Ipv6Address.fromString("::").isDefined, true)
assertEquals(Ipv6Address.fromString(" :: ").isDefined, true)
Expand All @@ -46,6 +47,10 @@ class Ipv6AddressTest extends BaseTestSuite {
}
}

test("parsing from string - does not misinterpret hosts") {
assertEquals(Ipv6Address.fromString("db"), None)
}

test("support converting to uncondensed string form") {
forAll(Gen.listOfN(16, Arbitrary.arbitrary[Byte])) { bytesList =>
if (bytesList.size == 16) {
Expand Down

0 comments on commit ee7a8f6

Please sign in to comment.