I'm using Yesod to write a personal backup system, and running into an interesting issue. I'm relatively inexperienced when it comes to Haskell so I'm sure none of this is optimal.
Here is one of my handlers:
postHostR :: Text -> RcPath -> Handler Text
postHostR hostName f = do
hostId <- insertIfDontExist hostName
tBody <- (T.pack . show) <$> getRawRequest
time <- lift getCurrentTime
newId <- runDB $ insert $ RcFile hostId tBody (makePath f) time
return $ T.pack $ show newId
Any of the text I retrieve from the DB has double quotes automatically added. I'm assuming this is some kind of XSS security but I'm not concerned about that since I'm not going to be rendering pages. The quotes don't seem to be actually part of the text (I've tried just stripping the first and last character, but that doesn't seem to actually remove the quotes).
Thanks!
The usual cause of this problem is that you have a string and you've called show on it when you didn't need to. (Most typically somebody does print x when they really wanted putStrLn x.)
In your case, I'm unsure of the type signatures, but I suspect that your final line can be changed from
return $ T.pack $ show newId
to just
return newId
I suspect newId is already Text, so calling show on it just puts unwanted quotes around it (and turns it into a String, which you then use T.pack to turn back into Text). If you just return it, it'll probably work.
(Then again, I could be completely mistaken about the type signature; it's hard to tell from here.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With