Skip to content

UUID: Quote the output of show #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions uuid-types/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.0

- Return a quoted string from the `Show` instance, to avoid confusing
packages which try to parse stock-derived `show` output.

## 1.0.6 (2023-04-16)

- Support GHC-8.6.5..GHC-9.10.1
Expand Down
17 changes: 9 additions & 8 deletions uuid-types/src/Data/UUID/Types/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -506,20 +506,21 @@ instance Hashable UUID where
`hashWithSalt` w2
`hashWithSalt` w3

-- | Pretty prints a 'UUID' (without quotation marks). See also 'toString'.
-- | Pretty prints a 'UUID'. See also 'toString'.
--
-- >>> show nil
-- "00000000-0000-0000-0000-000000000000"
-- "\"00000000-0000-0000-0000-000000000000\""
--
instance Show UUID where
show = toString
show = show . toString

instance Read UUID where
readsPrec _ str =
let noSpaces = dropWhile isSpace str
in case fromString (take 36 noSpaces) of
Nothing -> []
Just u -> [(u,drop 36 noSpaces)]
readsPrec p quotedStr = do
(str, rest) <- readsPrec p quotedStr
let noSpaces = dropWhile isSpace str
case fromString (take 36 noSpaces) of
Nothing -> []
Just u -> [(u, rest)]

-- | 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__.
instance Storable UUID where
Expand Down
2 changes: 1 addition & 1 deletion uuid-types/tests/TestUUID.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test_Binary =
(BL8.pack "\xa5\xca\x85\x66\xd9\xc5\x48\x35\x99\xc8\xe1\xf1\x3e\x73\xb5\xe2") @=? encode inputUUID

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

prop_stringRoundTrip :: Test
prop_stringRoundTrip = testProperty "String round trip" stringRoundTrip
Expand Down
2 changes: 1 addition & 1 deletion uuid-types/uuid-types.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 1.12
name: uuid-types
version: 1.0.6
version: 2.0.0
x-revision: 1
copyright:
(c) 2017-2018 Herbert Valerio Riedel
Expand Down