Merge pull request #30 from neilmayhew/detect-invalid-input

Detect invalid input
This commit is contained in:
Chris Done 2021-04-27 14:32:54 +01:00 committed by GitHub
commit 61d581ad00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 4 deletions

View File

@ -75,7 +75,6 @@ import Data.Char
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as M
import Data.Maybe
import Data.Monoid (Monoid)
import Data.Semigroup
import Data.Text (Text)
import qualified Data.Text as T
@ -246,7 +245,8 @@ iniParser :: Parser Ini
iniParser =
(\kv secs -> Ini {iniSections = M.fromList secs, iniGlobals = kv}) <$>
many keyValueParser <*>
many sectionParser
many sectionParser <*
(endOfInput <|> (fail . T.unpack =<< takeWhile (not . isControl)))
-- | A section. Format: @[foo]@. Conventionally, @[FOO]@.
sectionParser :: Parser (Text,[(Text, Text)])

View File

@ -1,7 +1,7 @@
# For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md
# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
resolver: lts-11.2
resolver: lts-16.31
# Local packages, usually specified by relative directory name
packages:

View File

@ -64,4 +64,11 @@ main =
]
, iniGlobals =
[("port", "6667"), ("hostname", "localhost")]
})))))
})))
it
"File with invalid keys"
(shouldBe
(parseIni
"Name=Foo\n\
\Name[en_GB]=Fubar")
(Left "Failed reading: Name[en_GB]=Fubar"))))