rustdoc: percent-encode URL fragments

This commit is contained in:
Jules Bertholet
2026-04-14 18:52:50 -04:00
parent cd061c73af
commit a9d7027f39
2 changed files with 14 additions and 2 deletions
+4 -2
View File
@@ -582,6 +582,7 @@ fn next(&mut self) -> Option<Self::Item> {
}
}
let id = self.id_map.derive(id);
let percent_encoded_id = small_url_encode(id.clone());
if let Some(ref mut builder) = self.toc {
let mut text_header = String::new();
@@ -596,8 +597,9 @@ fn next(&mut self) -> Option<Self::Item> {
std::cmp::min(level as u32 + (self.heading_offset as u32), MAX_HEADER_LEVEL);
self.buf.push_back((Event::Html(format!("</h{level}>").into()), 0..0));
let start_tags =
format!("<h{level} id=\"{id}\"><a class=\"doc-anchor\" href=\"#{id}\">§</a>");
let start_tags = format!(
"<h{level} id=\"{id}\"><a class=\"doc-anchor\" href=\"#{percent_encoded_id}\">§</a>"
);
return Some((Event::Html(start_tags.into()), 0..0));
}
event
+10
View File
@@ -0,0 +1,10 @@
#![crate_name = "unicode"]
pub struct Foo;
impl Foo {
//@ has unicode/struct.Foo.html //a/@href "#%C3%BA"
//@ !has unicode/struct.Foo.html //a/@href "#ú"
/// # ú
pub fn foo() {}
}