Skip to content

Commit

Permalink
Merge pull request #854 from notriddle/notriddle/issue-853-deeply-nes…
Browse files Browse the repository at this point in the history
…ted-parens

Use same limit for refdef as inline links
  • Loading branch information
Martin1887 committed Mar 2, 2024
2 parents ff80d0c + 8d598a8 commit 3525d2a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
10 changes: 10 additions & 0 deletions pulldown-cmark/specs/regression.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2501,3 +2501,13 @@ ISSUE 847
<!p>
<p>&lt;!p&gt;</p>
````````````````````````````````

ISSUE 853

```````````````````````````````` example
[linky]

[linky]: ((()))
.
<p><a href="((()))">linky</a></p>
````````````````````````````````
4 changes: 2 additions & 2 deletions pulldown-cmark/src/firstpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::cmp::max;
use std::ops::Range;

use crate::parse::{
scan_containers, Allocations, FootnoteDef, HeadingAttributes, Item, ItemBody, LinkDef,
scan_containers, Allocations, FootnoteDef, HeadingAttributes, Item, ItemBody, LinkDef, LINK_MAX_NESTED_PARENS,
};
use crate::strings::CowStr;
use crate::tree::{Tree, TreeIndex};
Expand Down Expand Up @@ -1678,7 +1678,7 @@ impl<'a, 'b> FirstPass<'a, 'b> {
let (mut i, _newlines) = self.scan_refdef_space(bytes, start)?;

// scan link dest
let (dest_length, dest) = scan_link_dest(self.text, i, 1)?;
let (dest_length, dest) = scan_link_dest(self.text, i, LINK_MAX_NESTED_PARENS)?;
if dest_length == 0 {
return None;
}
Expand Down
2 changes: 1 addition & 1 deletion pulldown-cmark/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::{Alignment, CodeBlockKind, Event, HeadingLevel, LinkType, Options, Ta
// The simplest countermeasure is to limit their depth, which is
// explicitly allowed by the spec as long as the limit is at least 3:
// https://spec.commonmark.org/0.29/#link-destination
const LINK_MAX_NESTED_PARENS: usize = 5;
pub(crate) const LINK_MAX_NESTED_PARENS: usize = 5;

#[derive(Debug, Default, Clone, Copy)]
pub(crate) struct Item {
Expand Down
12 changes: 12 additions & 0 deletions pulldown-cmark/tests/suite/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2988,3 +2988,15 @@ fn regression_test_188() {

test_markdown_html(original, expected, false, false, false);
}

#[test]
fn regression_test_189() {
let original = r##"[linky]
[linky]: ((()))
"##;
let expected = r##"<p><a href="((()))">linky</a></p>
"##;

test_markdown_html(original, expected, false, false, false);
}

0 comments on commit 3525d2a

Please sign in to comment.