From e030061c249fa5054bcdc1b26bb17a45a8b8db5c Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 3 Oct 2022 07:36:42 -0700 Subject: str-in6addr: bugfix: trailing zero in hex problem. * stdlib/socket.c (sys:in6addr-condensed-text): The regular expression used in calculating zr is incorrect; the zero in it can match the trailing zero of a nonzero quad, when the intent is only to match zero quads. Hack: we represent zero quads by the character Z and use that for the matching and removal of the longest range of zero quads. Then we filter the Z back to 0. --- stdlib/socket.tl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stdlib/socket.tl b/stdlib/socket.tl index af4aca4e..95a5650d 100644 --- a/stdlib/socket.tl +++ b/stdlib/socket.tl @@ -67,12 +67,14 @@ (defun sys:in6addr-condensed-text (numeric-pieces) - (let* ((str (cat-str [mapcar (op fmt "~x") numeric-pieces] ":")) - (zr (rra #/0(:0)+/ str)) + (let* ((str (cat-str [mapcar [iff zerop (ret "Z") (op fmt "~x")] + numeric-pieces] ":")) + (zr (rra #/Z(:Z)+/ str)) (lp [pos-max zr : [callf - to from]]) (lr [zr lp])) (when lp (del [str lr])) + (upd str (regsub "Z" "0")) (cond ((equal "" str) "::") ((starts-with ":" str) `:@str`) -- cgit v1.2.3