Skip to content

Commit

Permalink
Do not accept footnote definitions with line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle authored and jgm committed Oct 31, 2023
1 parent 0768897 commit 91444cb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
7 changes: 5 additions & 2 deletions commonmark-extensions/src/Commonmark/Extensions/Footnote.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,12 @@ footnoteBlockSpec = BlockSpec

pFootnoteLabel :: Monad m => ParsecT [Tok] u m Text
pFootnoteLabel = try $ do
lab <- pLinkLabel
lab <- untokenize
<$> try (between (symbol '[') (symbol ']')
(snd <$> withRaw (many
(pEscaped <|> noneOfToks [Symbol ']', Symbol '[', LineEnd]))))
case T.uncons lab of
Just ('^', t') | T.any (\x -> x /= ' ' && x /= '\t' && x /= '\r' && x /= '\n') t'
Just ('^', t') | T.any (\x -> x /= ' ' && x /= '\t') t' && T.all (\x -> x /= '\n' && x /= '\r') t'
-> return $! t'
_ -> mzero

Expand Down
38 changes: 38 additions & 0 deletions commonmark-extensions/test/footnotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,41 @@ Test [^] link [^ ]
<p>[^
]: not a footnote</p>
````````````````````````````````

Footnote labels cannot contain line breaks, even where link labels can.

```````````````````````````````` example
[^foo\
bar]: not a footnote definition
[baz\
quux]: https://haskell.org
[first
second]: https://haskell.org
[^third
fourth]: not a footnote definition
[baz\
quux]
[^foo\
bar]
[first
second]
[^third
fourth]
.
<p>[^foo<br />
bar]: not a footnote definition</p>
<p>[^third
fourth]: not a footnote definition</p>
<p><a href="https://haskell.org">baz<br />
quux</a>
[^foo<br />
bar]
<a href="https://haskell.org">first
second</a>
[^third
fourth]</p>
````````````````````````````````

0 comments on commit 91444cb

Please sign in to comment.