Fail parsing if the input isn't completely consumed

Without this, parsing stops at the start of any invalid input and
returns a successful result

Closes #29
This commit is contained in:
Neil Mayhew 2021-04-26 11:34:57 -06:00
parent 0c773d8ed8
commit 17659d59c2
2 changed files with 10 additions and 2 deletions

View File

@ -245,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

@ -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"))))