Skip to content
This repository has been archived by the owner on Aug 7, 2020. It is now read-only.

Commit

Permalink
disallow mixed backticks/tildes in code fence match
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Mar 11, 2020
1 parent 6237141 commit a483a91
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions mistletoe/block_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ class CodeFence(BlockToken):
"""Code fence. (["```sh\\n", "rm -rf /", ..., "```"])
Boundary between span-level and block-level tokens.
See <https://spec.commonmark.org/0.29/#fenced-code-blocks>
"""

children: ListType[Token] = attr.ib(
Expand All @@ -487,14 +489,18 @@ class CodeFence(BlockToken):
metadata={"doc": "Line position in source text (start, end)"}
)

pattern = re.compile(r"^( {0,3})((?:`|~){3,}) *([^`~\s]*) *([^`~]*)$")
# Tildes and backticks cannot be mixed.
pattern_tick = re.compile(r"^( {0,3})(`{3,}) *([^`\s]*) *([^`]*)$")
pattern_tilde = re.compile(r"^( {0,3})(~{3,}) *([^~\s]*) *([^~]*)$")
_open_info = None

@classmethod
def start(cls, line):
match_obj = cls.pattern.match(line)
match_obj = cls.pattern_tick.match(line)
if not match_obj:
return False
match_obj = cls.pattern_tilde.match(line)
if not match_obj:
return False
prepend, leader, lang, arguments = match_obj.groups()
if leader[0] in lang or leader[0] in line[match_obj.end() :]:
return False
Expand Down
2 changes: 1 addition & 1 deletion mistletoe/cli/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

commonmark_context = parse_context.ParseContext(
find_blocks=token_sets.get_commonmark_block_tokens(),
find_spans=token_sets.get_extended_span_tokens(),
find_spans=token_sets.get_commonmark_span_tokens(),
)
extended_context = parse_context.ParseContext(
find_blocks=token_sets.get_extended_block_tokens(),
Expand Down

0 comments on commit a483a91

Please sign in to comment.