From a51a554958fa295cd9557af4c107d57781b9b9f1 Mon Sep 17 00:00:00 2001 From: Adam Rocska Date: Thu, 7 May 2020 18:18:49 +0200 Subject: [PATCH] Fixed the broken tests. Signed-off-by: Adam Rocska --- Sources/MaxMindDBReader/IpAddress.swift | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Sources/MaxMindDBReader/IpAddress.swift b/Sources/MaxMindDBReader/IpAddress.swift index 6171e5e..e0440a2 100644 --- a/Sources/MaxMindDBReader/IpAddress.swift +++ b/Sources/MaxMindDBReader/IpAddress.swift @@ -45,17 +45,21 @@ public enum IpAddress: Equatable { } static func v6(_ string: String) -> IpAddress { - let inputRawChunks = string.split(separator: ":") + if string == "::1" { + print(string) + } + let inputRawChunks = string.split(separator: ":", omittingEmptySubsequences: false) precondition(inputRawChunks.count <= 8, "IPv6 strings must have at most 8 bytes defined.") var prefixBytes: [UInt8] = [] var suffixBytes: [UInt8] = [] - var shouldProcessPrefix = true + var emptyChunksFound = 0 for chunk in inputRawChunks { + precondition(chunk.count <= 4, "Invalid hexadectet provided : \"\(chunk)\".") if chunk.isEmpty { - if !shouldProcessPrefix { + if emptyChunksFound >= 2 { preconditionFailure("Invalid IPv6 format provided.") } - shouldProcessPrefix = false + emptyChunksFound += 1 continue } let hexadectet = String(repeating: "0", count: 4 - chunk.count) + chunk @@ -64,11 +68,11 @@ public enum IpAddress: Equatable { guard let byte1 = UInt8(hexadectet[..