From 8d159048ecabb0d32bce5f6767795d001b178066 Mon Sep 17 00:00:00 2001 From: Philipp Balzarek Date: Wed, 25 May 2016 20:15:47 +0200 Subject: [PATCH] Fix Jid Read instance using error (#102) --- source/Network/Xmpp/Types.hs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/source/Network/Xmpp/Types.hs b/source/Network/Xmpp/Types.hs index d0675dd..10f064c 100644 --- a/source/Network/Xmpp/Types.hs +++ b/source/Network/Xmpp/Types.hs @@ -894,16 +894,19 @@ instance Read Jid where readsPrec _ s = do -- Verifies that the first word is "parseJid", parses the second word and -- the remainder, if any, and produces these two values or fails. - let (s', r) = case lex s of - [] -> error "Expected `parseJid \"\"'" - [("parseJid", r')] -> case lex r' of - [] -> error "Expected `parseJid \"\"'" - [(s'', r'')] -> (s'', r'') - _ -> error "Expected `parseJid \"\"'" - _ -> error "Expected `parseJid \"\"'" - -- Read the JID string (removes the quotes), validate, and return. - [(parseJid (read s' :: String), r)] -- May fail with "Prelude.read: no parse" - -- or the `parseJid' error message (see below) + case lex s of + [("parseJid", r')] -> + case lex r' of + [(s', r'')] -> + case (reads s') of + ((jidTxt,_):_) -> + case jidFromText (Text.pack jidTxt) of + Nothing -> [] + Just jid' -> [(jid', r'')] + _ -> [] + _ -> [] + _ -> [] + #if WITH_TEMPLATE_HASKELL