shithub: mc

Download patch

ref: fdbd75fad30016627aa740bfeaa8592d0ec80d44
parent: 5dba8155dcecfd9f52856f5e658a189f2746c850
author: Ori Bernstein <ori@eigenstate.org>
date: Thu May 26 18:07:28 EDT 2016

Fix parsing ipv6 addresses.

	We need to actually pack the bytes into them
	when we reach the end. Er, fuck.

--- a/lib/std/ipparse.myr
+++ b/lib/std/ipparse.myr
@@ -69,21 +69,23 @@
 	for i = 0; ip.len > 0 && ok; i++
 		/* parse 'num' segment */
 		(v, ip, ok) = num(ip, 0, 65536, 16, ':', ok)
+
+		/* pack it into the bytes */
+		val[i*2] = ((v & 0xff00) >> 8 : byte)
+		val[i*2 + 1] = (v & 0xff : byte)
+
 		nseg++
 		if ip.len == 0 || nseg == 8
 			break
 		;;
+
 		(ip, ok) = delim(ip, ':', ok)
 		/* only one '::' allowed once */
 		if ip.len > 0 && ip[0] == (':' : byte) && !expand
+			(ip, ok) = delim(ip, ':', ok)
 			expand = true
 			split = i
-			(ip, ok) = delim(ip, ':', ok)
 		;;
-
-		/* pack it into the bytes */
-		val[i*2] = ((v & 0xff00) >> 8 : byte)
-		val[i*2 + 1] = (v & 0xff : byte)
 	;;
 
 	if ok && ip.len == 0
--- a/lib/std/test/ipparse.myr
+++ b/lib/std/test/ipparse.myr
@@ -29,6 +29,12 @@
 			0x00, 0x10, 0x00, 0x00,  \
 			0xfa, 0xce, 0xb0, 0x0c,  \
 			0x00, 0x00, 0x00, 0x01])
+	eq("2a03:2880:11:1f1b:face:b00c:0:25de", \
+		`std.Some `std.Ipv6 [ \
+			0x2a, 0x03, 0x28, 0x80, \
+			0x00, 0x11, 0x1f, 0x1b, \
+			0xfa, 0xce, 0xb0, 0x0c, \
+			0x00, 0x00, 0x25, 0xde])
 	eq("abcd::dcba", \
 		`std.Some `std.Ipv6 [ \
 			0xab, 0xcd, 0x00, 0x00, \