aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-07-14 13:16:20 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2015-07-14 13:16:40 -0700
commit9e0fb844a9f1d4b749854a775e4492f9e51e8fbf (patch)
tree74805f59aaaf89a7d744856c7818bfb8cf050dcf
parent9cdfd4f6491cbf9e3002e88be8be9ebeb48ba2bb (diff)
downloadpandoc-9e0fb844a9f1d4b749854a775e4492f9e51e8fbf.tar.gz
Markdown reader: don't allow bare URI links or autolinks in link label.
Added test cases. Closes #2300.
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs2
-rw-r--r--tests/Tests/Readers/Markdown.hs13
2 files changed, 14 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 3b5ae0978..b8f5dab60 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1752,12 +1752,14 @@ dropBrackets = reverse . dropRB . reverse . dropLB
bareURL :: MarkdownParser (F Inlines)
bareURL = try $ do
guardEnabled Ext_autolink_bare_uris
+ getState >>= guard . stateAllowLinks
(orig, src) <- uri <|> emailAddress
notFollowedBy $ try $ spaces >> htmlTag (~== TagClose "a")
return $ return $ B.link src "" (B.str orig)
autoLink :: MarkdownParser (F Inlines)
autoLink = try $ do
+ getState >>= guard . stateAllowLinks
char '<'
(orig, src) <- uri <|> emailAddress
-- in rare cases, something may remain after the uri parser
diff --git a/tests/Tests/Readers/Markdown.hs b/tests/Tests/Readers/Markdown.hs
index a041620e7..17bfd332e 100644
--- a/tests/Tests/Readers/Markdown.hs
+++ b/tests/Tests/Readers/Markdown.hs
@@ -194,7 +194,7 @@ tests = [ testGroup "inline code"
=?> para (link "/there.0" "" "hi")
]
, testGroup "bare URIs"
- (map testBareLink bareLinkTests)
+ (map testBareLink bareLinkTests)
, testGroup "autolinks"
[ "with unicode dash following" =:
"<http://foo.bar>\8212" =?> para (autolink "http://foo.bar" <>
@@ -203,6 +203,17 @@ tests = [ testGroup "inline code"
"<www.boe.es/buscar/act.php?id=BOE-A-1996-8930#a66>" =?>
para (text "<www.boe.es/buscar/act.php?id=BOE-A-1996-8930#a66>")
]
+ , testGroup "links"
+ [ "no autolink inside link" =:
+ "[<https://example.org>](url)" =?>
+ para (link "url" "" (text "<https://example.org>"))
+ , "no inline link inside link" =:
+ "[[a](url2)](url)" =?>
+ para (link "url" "" (text "[a](url2)"))
+ , "no bare URI inside link" =:
+ "[https://example.org(](url)" =?>
+ para (link "url" "" (text "https://example.org("))
+ ]
, testGroup "Headers"
[ "blank line before header" =:
"\n# Header\n"