Skip to content

Commit 7478f0b

Browse files
committed
UUID: Quote the output of show
Some packages (e.g., `pretty-simple`) expect strings to contain the output of `stock`-derived `show`. Using UUIDs with such libraries necessitates wrangling which can be easily avoided.
1 parent 68d7fe2 commit 7478f0b

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

uuid-types/ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.0.0
2+
3+
- Return a quoted string from the `Show` instance, to avoid confusing
4+
packages which try to parse stock-derived `show` output.
5+
16
## 1.0.6 (2023-04-16)
27

38
- Support GHC-8.6.5..GHC-9.10.1

uuid-types/src/Data/UUID/Types/Internal.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,14 +512,15 @@ instance Hashable UUID where
512512
-- "00000000-0000-0000-0000-000000000000"
513513
--
514514
instance Show UUID where
515-
show = toString
515+
show = show . toString
516516

517517
instance Read UUID where
518-
readsPrec _ str =
519-
let noSpaces = dropWhile isSpace str
520-
in case fromString (take 36 noSpaces) of
521-
Nothing -> []
522-
Just u -> [(u,drop 36 noSpaces)]
518+
readsPrec p quotedStr = do
519+
(str, rest) <- readsPrec p quotedStr
520+
let noSpaces = dropWhile isSpace str
521+
case fromString (take 36 noSpaces) of
522+
Nothing -> []
523+
Just u -> [(u, rest)]
523524

524525
-- | This 'Storable' instance uses the memory layout as described in <http://tools.ietf.org/html/rfc4122 RFC 4122>, but in contrast to the 'Binary' instance, __the fields are stored in host byte order__.
525526
instance Storable UUID where

uuid-types/tests/TestUUID.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ test_Binary =
8989
(BL8.pack "\xa5\xca\x85\x66\xd9\xc5\x48\x35\x99\xc8\xe1\xf1\x3e\x73\xb5\xe2") @=? encode inputUUID
9090

9191
inputUUID :: U.UUID
92-
inputUUID = read "a5ca8566-d9c5-4835-99c8-e1f13e73b5e2"
92+
inputUUID = read $ show "a5ca8566-d9c5-4835-99c8-e1f13e73b5e2"
9393

9494
prop_stringRoundTrip :: Test
9595
prop_stringRoundTrip = testProperty "String round trip" stringRoundTrip

uuid-types/uuid-types.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 1.12
22
name: uuid-types
3-
version: 1.0.6
3+
version: 2.0.0
44
x-revision: 1
55
copyright:
66
(c) 2017-2018 Herbert Valerio Riedel

0 commit comments

Comments
 (0)