Skip to content

Commit

Permalink
Rollup merge of rust-lang#68224 - GuillaumeGomez:prevent-urls-in-head…
Browse files Browse the repository at this point in the history
…ings, r=ollie27

Prevent urls in headings

Fixes rust-lang#68215.

cc @pietroalbini @ollie27

r? @kinnison
  • Loading branch information
Centril authored Jan 18, 2020
2 parents 733c7f4 + 298e8ad commit 36e58ea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,10 @@ impl<'a, 'b, 'ids, I: Iterator<Item = Event<'a>>> Iterator for HeadingLinks<'a,
}
_ => {}
}
self.buf.push_back(event);
match event {
Event::Start(Tag::Link(_, _, _)) | Event::End(Tag::Link(..)) => {}
event => self.buf.push_back(event),
}
}
let id = self.id_map.derive(id);

Expand All @@ -395,7 +398,7 @@ impl<'a, 'b, 'ids, I: Iterator<Item = Event<'a>>> Iterator for HeadingLinks<'a,

let start_tags = format!(
"<h{level} id=\"{id}\" class=\"section-header\">\
<a href=\"#{id}\">",
<a href=\"#{id}\">",
id = id,
level = level
);
Expand Down
17 changes: 17 additions & 0 deletions src/test/rustdoc/remove-url-from-headings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![crate_name = "foo"]

// @has foo/fn.foo.html
// !@has - '//a[@href="http://a.a"]'
// @has - '//a[@href="#implementing-stuff-somewhere"]' 'Implementing stuff somewhere'
// @has - '//a[@href="#another-one-urg"]' 'Another one urg'

/// fooo
///
/// # Implementing [stuff](http://a.a "title") somewhere
///
/// hello
///
/// # Another [one][two] urg
///
/// [two]: http://a.a
pub fn foo() {}

0 comments on commit 36e58ea

Please sign in to comment.