Skip to content

Commit 690b14e

Browse files
authored
Merge pull request #677 from kivikakk/push-olsuooroprtn
fix relaxed autolink email in footnote edge case/panic.
2 parents 42eb442 + 83ff06a commit 690b14e

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

src/parser/inlines.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,16 +1681,12 @@ impl<'a, 'r, 'o, 'd, 'c, 'p> Subject<'a, 'r, 'o, 'd, 'c, 'p> {
16811681
let bracket_inl_text = last.inl_text;
16821682

16831683
if self.options.extension.footnotes
1684-
&& match bracket_inl_text.next_sibling() {
1685-
Some(n) => {
1686-
if n.data().value.text().is_some() {
1687-
n.data().value.text().unwrap().as_bytes().starts_with(b"^")
1688-
} else {
1689-
false
1690-
}
1691-
}
1692-
_ => false,
1693-
}
1684+
&& bracket_inl_text.next_sibling().map_or(false, |n| {
1685+
n.data()
1686+
.value
1687+
.text()
1688+
.map_or(false, |t| t.as_bytes().starts_with(b"^"))
1689+
})
16941690
{
16951691
let mut text = String::new();
16961692
let mut sibling_iterator = bracket_inl_text.following_siblings();
@@ -1704,6 +1700,15 @@ impl<'a, 'r, 'o, 'd, 'c, 'p> Subject<'a, 'r, 'o, 'd, 'c, 'p> {
17041700
// For example `[^_foo]` gives `^`, `_`, and `foo`. So pull them together.
17051701
// Since we're handling the closing bracket, the only siblings at this point are
17061702
// related to the footnote name.
1703+
//
1704+
// This re-construction of the original text value is an awful HACK
1705+
// we should reconsider. Can't we go back to the subject and pull
1706+
// it from there?
1707+
1708+
// If there's a non-Text/HtmlInline, such as SoftBreak, don't try to
1709+
// do anything fancy here at all.
1710+
let mut sussy = false;
1711+
17071712
for sibling in sibling_iterator {
17081713
match sibling.data().value {
17091714
NodeValue::Text(ref literal) => {
@@ -1712,11 +1717,14 @@ impl<'a, 'r, 'o, 'd, 'c, 'p> Subject<'a, 'r, 'o, 'd, 'c, 'p> {
17121717
NodeValue::HtmlInline(ref literal) => {
17131718
text.push_str(literal);
17141719
}
1715-
_ => {}
1720+
_ => {
1721+
sussy = true;
1722+
break;
1723+
}
17161724
};
17171725
}
17181726

1719-
if text.len() > 1 {
1727+
if !sussy && text.len() > 1 {
17201728
let inl = self.make_inline(
17211729
NodeValue::FootnoteReference(NodeFootnoteReference {
17221730
name: text[1..].to_string(),

src/tests/fuzz.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,6 @@ fn echaw9() {
357357
}
358358

359359
#[test]
360-
// FIXME
361-
#[should_panic = "assertion failed: (sp.end.column - sp.start.column + 1 == x) || rem == 0"]
362360
fn relaxed_autolink_email_in_footnote() {
363361
assert_ast_match!(
364362
[
@@ -367,8 +365,15 @@ fn relaxed_autolink_email_in_footnote() {
367365
parse.relaxed_autolinks
368366
],
369367
"[^[email protected]\nA]:\n",
370-
(document (1:1-1:1234) [
371-
// TODO: what should this be parsed as?
368+
(document (1:1-2:3) [
369+
(paragraph (1:1-2:3) [
370+
(text (1:1-1:2) "[^")
371+
(link (1:3-1:7) "mailto:[email protected]" [
372+
(text (1:3-1:7) "[email protected]")
373+
])
374+
(softbreak (1:8-1:8))
375+
(text (2:1-2:3) "A]:")
376+
])
372377
]),
373378
);
374379
}

0 commit comments

Comments
 (0)