Browse Source

improve error reporting in case of leading or trailign white spaces in a quoted JID

master
Philipp Balzarek 13 years ago
parent
commit
2168283315
  1. 18
      source/Network/Xmpp/Types.hs

18
source/Network/Xmpp/Types.hs

@ -78,8 +78,8 @@ import Data.Text (Text)
import qualified Data.Text as Text import qualified Data.Text as Text
import Data.Typeable(Typeable) import Data.Typeable(Typeable)
import Data.XML.Types import Data.XML.Types
import Language.Haskell.TH.Quote
import Language.Haskell.TH import Language.Haskell.TH
import Language.Haskell.TH.Quote
import Network import Network
import Network.DNS import Network.DNS
import Network.TLS hiding (Version) import Network.TLS hiding (Version)
@ -965,12 +965,16 @@ instance Read Jid where
-- or the `parseJid' error message (see below) -- or the `parseJid' error message (see below)
jidQ :: QuasiQuoter jidQ :: QuasiQuoter
jidQ = QuasiQuoter { quoteExp = \s -> case jidFromText (Text.pack s) of jidQ = QuasiQuoter { quoteExp = \s -> do
Nothing -> fail $ "Could not parse JID " ++ s when (head s == ' ') . fail $ "Leading whitespaces in JID" ++ show s
Just j -> [| Jid $(mbTextE $ localpart_ j) let t = Text.pack s
$(textE $ domainpart_ j) when (Text.last t == ' ') . reportWarning $ "Trailing whitespace in JID " ++ show s
$(mbTextE $ resourcepart_ j) case jidFromText t of
|] Nothing -> fail $ "Could not parse JID " ++ s
Just j -> [| Jid $(mbTextE $ localpart_ j)
$(textE $ domainpart_ j)
$(mbTextE $ resourcepart_ j)
|]
, quotePat = fail "Jid patterns aren't implemented" , quotePat = fail "Jid patterns aren't implemented"
, quoteType = fail "jid QQ can't be used in type context" , quoteType = fail "jid QQ can't be used in type context"
, quoteDec = fail "jid QQ can't be used in declaration context" , quoteDec = fail "jid QQ can't be used in declaration context"

Loading…
Cancel
Save