diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2025-09-14 01:32:20 +0200 |
|---|---|---|
| committer | León Orell Valerian Liehr <me@fmease.dev> | 2025-09-25 11:30:58 +0200 |
| commit | d7d7725b8cbeea8db490c3b033773776ce8794f5 (patch) | |
| tree | dccb7c948e48bc87f72f4e8b1405cbeed45d5447 /src/librustdoc/html/render/mod.rs | |
| parent | 88e797784e21ecad4dc768109ede33c76293482e (diff) | |
| download | rust-d7d7725b8cbeea8db490c3b033773776ce8794f5.tar.gz rust-d7d7725b8cbeea8db490c3b033773776ce8794f5.zip | |
rustdoc: Fully escape link section and export name
Escape "special characters" (e.g., double quotes `"` and line breaks `\n`). Escape HTML. Lastly, add regression tests and clean up existing tests.
Diffstat (limited to 'src/librustdoc/html/render/mod.rs')
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 4b7822cd3a9..9280701ea3f 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2935,11 +2935,11 @@ fn render_attributes_in_code( let hir::Attribute::Parsed(kind) = attr else { continue }; let attr = match kind { AttributeKind::LinkSection { name, .. } => { - Cow::Owned(format!("#[unsafe(link_section = \"{name}\")]")) + Cow::Owned(format!("#[unsafe(link_section = {})]", Escape(&format!("{name:?}")))) } AttributeKind::NoMangle(..) => Cow::Borrowed("#[unsafe(no_mangle)]"), AttributeKind::ExportName { name, .. } => { - Cow::Owned(format!("#[unsafe(export_name = \"{name}\")]")) + Cow::Owned(format!("#[unsafe(export_name = {})]", Escape(&format!("{name:?}")))) } AttributeKind::NonExhaustive(..) => Cow::Borrowed("#[non_exhaustive]"), _ => continue, |
