Skip to content

Commit

Permalink
contacts: type check fields without crashing in +sane-contact
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolajpp committed Oct 14, 2024
1 parent 306c439 commit c58ef16
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions desk/lib/contacts.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@
::
++ cy
|_ c=contact
:: +typ: enforce type if value exists
::
++ typ
|* [key=@tas typ=value-type]
^- ?
=/ val=(unit value) (~(get by c) key)
?~ val &
?~ u.val |
?- typ
%text ?=(%text -.u.val)
%numb ?=(%numb -.u.val)
%date ?=(%date -.u.val)
%tint ?=(%tint -.u.val)
%ship ?=(%ship -.u.val)
%look ?=(%look -.u.val)
%flag ?=(%flag -.u.val)
%set ?=(%set -.u.val)
==
:: +get: typed get
::
++ get
Expand Down Expand Up @@ -160,21 +178,25 @@
:: 3. data URLs in %avatar and %cover
:: are forbidden
::
?. (~(typ cy con) %nickname %text) |
=+ nickname=(~(get cy con) %nickname %text)
?: ?& ?=(^ nickname)
(gth (met 3 u.nickname) 64)
==
|
?. (~(typ cy con) %bio %text) |
=+ bio=(~(get cy con) %bio %text)
?: ?& ?=(^ bio)
(gth (met 3 u.bio) 2.048)
==
|
?. (~(typ cy con) %avatar %look) |
=+ avatar=(~(get cy con) %avatar %look)
?: ?& ?=(^ avatar)
=('data:' (end 3^5 u.avatar))
==
|
?. (~(typ cy con) %cover %look) |
=+ cover=(~(get cy con) %cover %look)
?: ?& ?=(^ cover)
=('data:' (end 3^5 u.cover))
Expand Down

0 comments on commit c58ef16

Please sign in to comment.