Merge pull request #1664

This commit is contained in:
autocraft-bot[bot] committed 2026-11-29 00:13:31 +00:00
commit fb4524b889
2 files changed
+24 -1

No files matched your search

+1 -1
View File
@@ -428,7 +428,7 @@ fn angle_inlines(s: &str, start: usize, base: &Fmt) -> Option<(usize, Vec<Node>)
} else if matches!(lower.trim_end_matches('/').trim(), "br") {
push_text(&mut nodes, "\n", base);
Some((end, nodes))
} else if lower.starts_with("a ") && rest.get(inner.len() + 1..).is_some_and(|tail| tail.to_ascii_lowercase().starts_with("</a>")) {
} else if lower.starts_with("a ") && rest.get(inner.len() + 1..).and_then(|tail| tail.get(..4)).is_some_and(|p| p.eq_ignore_ascii_case("</a>")) {
if let Some(name) = tag_attr(inner, "id").or_else(|| tag_attr(inner, "name")) {
nodes.push(Node::Inl(Inline::Anchor(name)));
}
+23
View File
@@ -21,6 +21,29 @@ fn emphasis() {
assert!(matches!(&s[0], Inline::Text(t, f) if t == "gone" && f.strike));
}
/// An empty `<a id>` or `<a name>` is an anchor whatever the case of its `</a>` (wordcraft#3715).
#[test]
fn empty_html_anchor() {
let anchors = |s: &str| inl(s).into_iter().filter_map(|i| if let Inline::Anchor(a) = i { Some(a) } else { None }).collect::<Vec<_>>();
assert_eq!(anchors(r#"x <a id="n"></a> y"#), vec!["n"]);
assert_eq!(anchors(r#"x <a name="m"></A> y"#), vec!["m"]);
assert_eq!(anchors(r#"<A id="p"></a>"#), vec!["p"]);
assert!(anchors(r#"<a id="n">text</a>"#).is_empty());
assert!(anchors(r#"<a id="n"></"#).is_empty());
assert!(anchors(r#"<a id="n"></aé"#).is_empty());
}
/// Every `<a …>` tag lower-cased a copy of the rest of its paragraph to look for `</a>`
/// (wordcraft#3715): quadratic on a paragraph of tags.
#[test]
fn a_paragraph_of_anchor_tags_parses_in_linear_time() {
let src = "<a x>".repeat(1_000_000);
let t = std::time::Instant::now();
inl(&src);
// Well under a second now; the per-tag copy took 40 s in a release build.
assert!(t.elapsed() < std::time::Duration::from_secs(10), "{:?}", t.elapsed());
}
#[test]
fn links_code_escapes() {
let s = inl("see [the *site*](http://x.org \"T\") and `a*b*` \\*lit\\* &amp; <https://y.com>");