diff options
| author | bptato <nincsnevem662@gmail.com> | 2023-07-07 14:12:40 +0200 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2023-07-07 14:13:19 +0200 |
| commit | a84193b0af85cc1e4c298d66a6fd951e0e46b480 (patch) | |
| tree | 87ba336c353eaa3ce6bf75b43422b02082403b03 /src/types | |
| parent | b2514e94bac6f7b3462649834ad36287b0b29ab2 (diff) | |
| download | chawan-a84193b0af85cc1e4c298d66a6fd951e0e46b480.tar.gz | |
Fixes in ipv6 parser and serializer
Diffstat (limited to 'src/types')
| -rw-r--r-- | src/types/url.nim | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/types/url.nim b/src/types/url.nim index 727d7b84..bfdc3eaa 100644 --- a/src/types/url.nim +++ b/src/types/url.nim @@ -148,13 +148,17 @@ func parseIpv6(input: string): Option[array[8, uint16]] = #TODO validation error return failure break - elif has and c == ':': - inc pointer - if not has: + elif has: + if c == ':': + inc pointer + if not has: + #TODO validation error + return failure + else: #TODO validation error return failure - address[pieceindex] = value - inc pieceindex + address[pieceindex] = value + inc pieceindex if compress != -1: var swaps = pieceindex - compress pieceindex = 7 @@ -574,7 +578,6 @@ proc basicParseUrl*(input: string, base = none(URL), url: URL = URL(), if buffer != "": let i = parseInt32(buffer) if i.isNone or i.get notin 0..65535: - eprint "validation error???", i #TODO validation error return none(Url) let port = cast[uint16](i.get).some @@ -798,11 +801,7 @@ func serializeip(ipv6: array[8, uint16]): string = result &= ':' ignore0 = true continue - const HexChars = "0123456789abcdef" - var x = ipv6[i] - while x != 0: - result &= HexChars[x mod 0x10] - x = x div 0x10 + result &= toHexLower(ipv6[i]) if i != high(ipv6): result &= ':' |