diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-10-03 07:36:42 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-10-03 07:36:42 -0700 |
commit | e030061c249fa5054bcdc1b26bb17a45a8b8db5c (patch) | |
tree | 72fae219bfe6ff4f701f33b5eb545201135c55fd | |
parent | 5fb8a7fff19e0f7326181aeb55814061aac0b205 (diff) | |
download | txr-e030061c249fa5054bcdc1b26bb17a45a8b8db5c.tar.gz txr-e030061c249fa5054bcdc1b26bb17a45a8b8db5c.tar.bz2 txr-e030061c249fa5054bcdc1b26bb17a45a8b8db5c.zip |
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.
-rw-r--r-- | stdlib/socket.tl | 6 |
1 files 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`) |