aboutsummaryrefslogtreecommitdiff
path: root/haddock-library/test
diff options
context:
space:
mode:
authorAlec Theriault <alec.theriault@gmail.com>2020-03-27 20:16:51 -0400
committerAlec Theriault <alec.theriault@gmail.com>2020-03-27 20:34:33 -0400
commitb0514cc5d53bb37424177d2ba986216a914f8b1c (patch)
treee67847ed5e4ecc907c710cabc0397ce39df7d589 /haddock-library/test
parent8c6532636e6bd572455dfcf0b0d6e05f7033d110 (diff)
Fix crash in `haddock-library` on unicode space
Our quickcheck tests for `haddock-library` stumbled across an edge case input that was causing Haddock to crash: it was a unicode space character. The root cause of the crash is that we were implicitly assuming that if a space character was not " \t\f\v\r", it would have to be "\n". We fix this by instead defining horizontal space as: any space character that is not '\n'. Fixes #1142
Diffstat (limited to 'haddock-library/test')
-rw-r--r--haddock-library/test/Documentation/Haddock/ParserSpec.hs8
1 files changed, 7 insertions, 1 deletions
diff --git a/haddock-library/test/Documentation/Haddock/ParserSpec.hs b/haddock-library/test/Documentation/Haddock/ParserSpec.hs
index bc40a0a2..8b59b560 100644
--- a/haddock-library/test/Documentation/Haddock/ParserSpec.hs
+++ b/haddock-library/test/Documentation/Haddock/ParserSpec.hs
@@ -3,6 +3,7 @@
module Documentation.Haddock.ParserSpec (main, spec) where
+import Data.Char (isSpace)
import Data.String
import qualified Documentation.Haddock.Parser as Parse
import Documentation.Haddock.Types
@@ -442,6 +443,10 @@ spec = do
property $ \xs ->
(length . show . parseParas) xs `shouldSatisfy` (> 0)
+ -- See <https://github.com/haskell/haddock/issues/1142>
+ it "doesn't crash on unicode whitespace" $ do
+ "\8197" `shouldParseTo` DocEmpty
+
context "when parsing @since" $ do
it "adds specified version to the result" $ do
parseParas "@since 0.5.0" `shouldBe`
@@ -470,7 +475,8 @@ spec = do
context "when parsing text paragraphs" $ do
- let filterSpecial = filter (`notElem` (".(=#-[*`\v\f\n\t\r\\\"'_/@<> " :: String))
+ let isSpecial c = isSpace c || c `elem` (".(=#-[*`\\\"'_/@<>" :: String)
+ filterSpecial = filter (not . isSpecial)
it "parses an empty paragraph" $ do
"" `shouldParseTo` DocEmpty