1
0
forked from GitHub/gf-core

fix: PGFService should type-check the trees that comes from the user

This commit is contained in:
krasimir
2010-07-31 10:45:59 +00:00
parent e2d0c82f0c
commit fefd78222a
2 changed files with 13 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ import URLEncoding
import Network.FastCGI
import Text.JSON
import Text.PrettyPrint (render, text, (<+>))
import qualified Codec.Binary.UTF8.String as UTF8 (encodeString, decodeString)
import qualified Data.ByteString.Lazy as BS
@@ -65,9 +66,16 @@ pgfMain pgf command =
getText = liftM (maybe "" (urlDecodeUnicode . UTF8.decodeString)) $ getInput "input"
getTree :: CGI PGF.Tree
getTree = do mt <- getInput "tree"
t <- maybe (throwCGIError 400 "No tree given" ["No tree given"]) return mt
maybe (throwCGIError 400 "Bad tree" ["Bad tree: " ++ t]) return (PGF.readExpr t)
getTree = do ms <- getInput "tree"
s <- maybe (throwCGIError 400 "No tree given" ["No tree given"]) return ms
t <- maybe (throwCGIError 400 "Bad tree" ["tree: " ++ s]) return (PGF.readExpr s)
t <- either (\err -> throwCGIError 400 "Type incorrect tree"
["tree: " ++ PGF.showExpr [] t
,render (text "error:" <+> PGF.ppTcError err)
])
(return . fst)
(PGF.inferExpr pgf t)
return t
getCat :: CGI (Maybe PGF.Type)
getCat =

View File

@@ -18,7 +18,8 @@ executable pgf-server
fastcgi >= 3001.0.2.2,
json >= 0.3.3,
utf8-string >= 0.3.1.1,
bytestring
bytestring,
pretty
if !os(windows)
build-depends: unix
main-is: PGFService.hs