diff options
| author | jasonzoladz <jasonzoladz@gmail.com> | 2017-01-28 12:06:28 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-01-28 12:06:28 -0500 |
| commit | 140c7df6fb928d5e90931873d62f577f4be863ba (patch) | |
| tree | 46a256d0082de46ad536de60d745c89ac2a7a6df | |
| parent | 3e991adf4eaeac4da4d074992a507d651b81733f (diff) | |
| download | graphql-140c7df6fb928d5e90931873d62f577f4be863ba.tar.gz | |
Fix Int32 bounds checking in Value parser.
| -rw-r--r-- | Data/GraphQL/Parser.hs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Data/GraphQL/Parser.hs b/Data/GraphQL/Parser.hs index 2e72a3a..e1dc654 100644 --- a/Data/GraphQL/Parser.hs +++ b/Data/GraphQL/Parser.hs @@ -8,6 +8,7 @@ import Control.Applicative ((<|>), empty, many, optional) import Control.Monad (when) import Data.Char (isDigit, isSpace) import Data.Foldable (traverse_) +import Data.Int (Int32) import Data.Scientific (floatingOrInteger) import Data.Text (Text, append) @@ -147,7 +148,7 @@ typeCondition = namedType value :: Parser Value value = ValueVariable <$> variable -- TODO: Handle maxBound, Int32 in spec. - <|> tok (either ValueFloat ValueInt . floatingOrInteger <$> scientific) + <|> tok floatOrInt32Value <|> ValueBoolean <$> booleanValue <|> ValueString <$> stringValue -- `true` and `false` have been tried before @@ -156,6 +157,16 @@ value = ValueVariable <$> variable <|> ValueObject <$> objectValue <?> "value error!" +floatOrInt32Value :: Parser Value +floatOrInt32Value = do + n <- scientific + case (floatingOrInteger n :: Either Double Integer) of + Left dbl -> return $ ValueFloat dbl + Right i -> + if i < (-2147483648) || i >= 2147483648 + then fail "Integer value is out of range." + else return $ ValueInt (fromIntegral i :: Int32) + booleanValue :: Parser Bool booleanValue = True <$ tok "true" <|> False <$ tok "false" |
