Skip to content

Commit

Permalink
fix: no "assertion failed" caused by cut link definition
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatyang committed Jan 17, 2021
1 parent f9e9749 commit a09c4cb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
21 changes: 21 additions & 0 deletions corpus/issues.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,27 @@ ss_*.
(paragraph
(text)))

================================================================================
#14 - Assertion failed caused by cut link definition
================================================================================
[`]:
a
b
c

--------------------------------------------------------------------------------

(document
(link_reference_definition
(link_label
(text))
(link_destination
(text)))
(paragraph
(text)
(soft_line_break)
(text)))

================================================================================
#16 - infinite loop caused by overlapped delimiter range
================================================================================
Expand Down
3 changes: 3 additions & 0 deletions src/tree_sitter_markdown/block_delimiter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ unsigned BlockDelimiterList::deserialize(const unsigned char *buffer) {

void BlockDelimiterList::pop_front() { list_.pop_front(); }
void BlockDelimiterList::push_back(const BlockDelimiter &dlm) { list_.push_back(dlm); }
BlockDelimiterList::Iterator BlockDelimiterList::insert(const BlockDelimiterList::Iterator itr, const BlockDelimiter &dlm) {
return list_.insert(itr, dlm);
}
BlockDelimiterList::Iterator BlockDelimiterList::insert(const LexedRow row, const BlockDelimiter &dlm) {
Iterator itr = list_.begin();
Iterator end = list_.end();
Expand Down
1 change: 1 addition & 0 deletions src/tree_sitter_markdown/block_delimiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct BlockDelimiterList {

void pop_front();
void push_back(const BlockDelimiter &delimiter);
Iterator insert(const Iterator itr, const BlockDelimiter &delimiter);
Iterator insert(const LexedRow row, const BlockDelimiter &delimiter);
Iterator erase(Iterator iterator, Iterator end_iterator);

Expand Down
3 changes: 3 additions & 0 deletions src/tree_sitter_markdown/inline_scan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,9 @@ void hdl_unpaired_inl_dlm(Lexer &lxr, InlineDelimiterList &inl_dlms, InlineConte
lxr.cur_row(),
BlockDelimiter(SYM_LNK_REF_DEF_END_MKR, lxr.cur_pos(), lxr.cur_pos())
);
if (lnk_ref_def_end_mkr_nxt_itr != blk_dlms.end() && lnk_ref_def_end_mkr_nxt_itr->sym() == SYM_LIT_LBK) {
lnk_ref_def_end_mkr_nxt_itr = ++blk_dlms.insert(++lnk_ref_def_end_mkr_nxt_itr, BlockDelimiter(SYM_PGH_BGN_MKR, 0));
}
while (lnk_ref_def_end_mkr_nxt_itr != blk_dlms.end()) {
if (lnk_ref_def_end_mkr_nxt_itr->sym() == SYM_PGH_END_MKR) {
blk_dlms.erase(lnk_ref_def_end_mkr_nxt_itr, blk_dlms.end());
Expand Down

0 comments on commit a09c4cb

Please sign in to comment.