Skip to content

Commit

Permalink
Fix bug with entities inside link destinations.
Browse files Browse the repository at this point in the history
The bug affects cases like this: `[link](\!)`; the backslash
escape was being ignored here.

Closes #149.
  • Loading branch information
jgm committed Mar 6, 2024
1 parent d3a486a commit 72b59ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 7 additions & 4 deletions commonmark/src/Commonmark/Inlines.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ import Data.Maybe (isJust, mapMaybe, listToMaybe)
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as T
import Commonmark.Entity (unEntity, charEntity, numEntity)
import Commonmark.Entity (unEntity, charEntity, numEntity,
pEntity)
import Text.Parsec hiding (State, space)
import Text.Parsec.Pos

Expand Down Expand Up @@ -906,7 +907,7 @@ pInlineLink :: Monad m => ParsecT [Tok] s m LinkInfo
pInlineLink = try $ do
_ <- symbol '('
optional whitespace
target <- unEntity <$> pLinkDestination
target <- untokenize <$> pLinkDestination
optional whitespace
title <- option "" $
unEntity <$> (pLinkTitle <* optional whitespace)
Expand All @@ -922,7 +923,8 @@ pLinkDestination = pAngleDest <|> pNormalDest 0
pAngleDest = do
_ <- symbol '<'
res <- many (noneOfToks [Symbol '<', Symbol '>', Symbol '\\',
LineEnd] <|> pEscaped)
Symbol '&', LineEnd]
<|> pEscaped <|> pEntity <|> symbol '&')
_ <- symbol '>'
return res

Expand All @@ -935,7 +937,8 @@ pLinkDestination = pAngleDest <|> pNormalDest 0
pNormalDest' numparens
| numparens > 32 = mzero
| otherwise = (do
t <- satisfyTok (\case
t <- pEntity <|>
satisfyTok (\case
Tok (Symbol '\\') _ _ -> True
Tok (Symbol ')') _ _ -> numparens >= 1
Tok Spaces _ _ -> False
Expand Down
11 changes: 11 additions & 0 deletions commonmark/test/regression.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,14 @@ Issue #142
<!x
>
````````````````````````````````

Issue #149
```````````````````````````````` example
[link](\&#33;)
[link](&#33;)
.
<p><a href="&amp;#33;">link</a></p>
<p><a href="!">link</a></p>
````````````````````````````````

Expand Down

0 comments on commit 72b59ad

Please sign in to comment.