Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Forbid spaces in anchors (#1148) #1151

Merged
merged 1 commit into from
Mar 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion haddock-library/src/Documentation/Haddock/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ takeWhile1_ = mfilter (not . T.null) . takeWhile_
-- DocAName "Hello world"
anchor :: Parser (DocH mod a)
anchor = DocAName . T.unpack <$>
disallowNewline ("#" *> takeWhile1_ (/= '#') <* "#")
("#" *> takeWhile1_ (\x -> x /= '#' && not (isSpace x)) <* "#")

-- | Monospaced strings.
--
Expand Down
2 changes: 1 addition & 1 deletion haddock-library/src/Documentation/Haddock/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ data DocH mod id
| DocMathInline String
| DocMathDisplay String
| DocAName String
-- ^ A (HTML) anchor.
-- ^ A (HTML) anchor. It must not contain any spaces.
| DocProperty String
| DocExamples [Example]
| DocHeader (Header (DocH mod id))
Expand Down
9 changes: 7 additions & 2 deletions haddock-library/test/Documentation/Haddock/ParserSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,10 @@ spec = do
it "parses a single word anchor" $ do
"#foo#" `shouldParseTo` DocAName "foo"

it "parses a multi word anchor" $ do
"#foo bar#" `shouldParseTo` DocAName "foo bar"
-- Spaces are not allowed:
-- https://www.w3.org/TR/html51/dom.html#the-id-attribute
it "doesn't parse a multi word anchor" $ do
"#foo bar#" `shouldParseTo` "#foo bar#"

it "parses a unicode anchor" $ do
"#灼眼のシャナ#" `shouldParseTo` DocAName "灼眼のシャナ"
Expand All @@ -304,6 +306,9 @@ spec = do
it "does not accept empty anchors" $ do
"##" `shouldParseTo` "##"

it "does not accept anchors containing spaces" $ do
"{-# LANGUAGE GADTs #-}" `shouldParseTo` "{-# LANGUAGE GADTs #-}"

context "when parsing emphasised text" $ do
it "emphasises a word on its own" $ do
"/foo/" `shouldParseTo` DocEmphasis "foo"
Expand Down