Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions src/parser/inlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1681,16 +1681,12 @@ impl<'a, 'r, 'o, 'd, 'c, 'p> Subject<'a, 'r, 'o, 'd, 'c, 'p> {
let bracket_inl_text = last.inl_text;

if self.options.extension.footnotes
&& match bracket_inl_text.next_sibling() {
Some(n) => {
if n.data().value.text().is_some() {
n.data().value.text().unwrap().as_bytes().starts_with(b"^")
} else {
false
}
}
_ => false,
}
&& bracket_inl_text.next_sibling().map_or(false, |n| {
n.data()
.value
.text()
.map_or(false, |t| t.as_bytes().starts_with(b"^"))
})
{
let mut text = String::new();
let mut sibling_iterator = bracket_inl_text.following_siblings();
Expand All @@ -1704,6 +1700,15 @@ impl<'a, 'r, 'o, 'd, 'c, 'p> Subject<'a, 'r, 'o, 'd, 'c, 'p> {
// For example `[^_foo]` gives `^`, `_`, and `foo`. So pull them together.
// Since we're handling the closing bracket, the only siblings at this point are
// related to the footnote name.
//
// This re-construction of the original text value is an awful HACK
// we should reconsider. Can't we go back to the subject and pull
// it from there?

// If there's a non-Text/HtmlInline, such as SoftBreak, don't try to
// do anything fancy here at all.
let mut sussy = false;

for sibling in sibling_iterator {
match sibling.data().value {
NodeValue::Text(ref literal) => {
Expand All @@ -1712,11 +1717,14 @@ impl<'a, 'r, 'o, 'd, 'c, 'p> Subject<'a, 'r, 'o, 'd, 'c, 'p> {
NodeValue::HtmlInline(ref literal) => {
text.push_str(literal);
}
_ => {}
_ => {
sussy = true;
break;
}
};
}

if text.len() > 1 {
if !sussy && text.len() > 1 {
let inl = self.make_inline(
NodeValue::FootnoteReference(NodeFootnoteReference {
name: text[1..].to_string(),
Expand Down
13 changes: 9 additions & 4 deletions src/tests/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,6 @@ fn echaw9() {
}

#[test]
// FIXME
#[should_panic = "assertion failed: (sp.end.column - sp.start.column + 1 == x) || rem == 0"]
fn relaxed_autolink_email_in_footnote() {
assert_ast_match!(
[
Expand All @@ -367,8 +365,15 @@ fn relaxed_autolink_email_in_footnote() {
parse.relaxed_autolinks
],
"[^[email protected]\nA]:\n",
(document (1:1-1:1234) [
// TODO: what should this be parsed as?
(document (1:1-2:3) [
(paragraph (1:1-2:3) [
(text (1:1-1:2) "[^")
(link (1:3-1:7) "mailto:[email protected]" [
(text (1:3-1:7) "[email protected]")
])
(softbreak (1:8-1:8))
(text (2:1-2:3) "A]:")
])
]),
);
}
Expand Down