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 | 82bab2edc729eacf73c04290be7c68abe0baca0b (patch) | |
tree | 72fae219bfe6ff4f701f33b5eb545201135c55fd /stdlib | |
parent | 16272e28b07167948d93c5000a5fec16664f51d2 (diff) | |
download | txr-82bab2edc729eacf73c04290be7c68abe0baca0b.tar.gz txr-82bab2edc729eacf73c04290be7c68abe0baca0b.tar.bz2 txr-82bab2edc729eacf73c04290be7c68abe0baca0b.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.
Diffstat (limited to 'stdlib')
-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`) |