Skip to content

Commit

Permalink
rustdoc: make calls of markdown::render safer
Browse files Browse the repository at this point in the history
Previously, external code might call `markdown::render()` without having
called `markdown::reset_headers()`, meaning the TLS key
`used_header_map` was unset.  Now `markdown::render()` ensures that
`used_header_map` is set by calling `reset_headers` if necessary.

Fix #17736
  • Loading branch information
tomjakubowski committed Oct 6, 2014
1 parent dfbe9eb commit 942bed7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
text.with_c_str(|p| unsafe { hoedown_buffer_puts(ob, p) });
}

if used_header_map.get().is_none() {
reset_headers();
}

unsafe {
let ob = hoedown_buffer_new(DEF_OUNIT);
let renderer = hoedown_html_renderer_new(0, 0);
Expand Down Expand Up @@ -446,7 +450,7 @@ impl<'a> fmt::Show for MarkdownWithToc<'a> {

#[cfg(test)]
mod tests {
use super::LangString;
use super::{LangString, Markdown};

#[test]
fn test_lang_string_parse() {
Expand Down Expand Up @@ -474,4 +478,10 @@ mod tests {
t("{.example .rust}", false,false,false,false,false);
t("{.test_harness .rust}", false,false,false,false,true);
}

#[test]
fn issue_17736() {
let markdown = "# title";
format!("{}", Markdown(markdown.as_slice()));
}
}

5 comments on commit 942bed7

@bors
Copy link
Contributor

@bors bors commented on 942bed7 Oct 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at tomjakubowski@942bed7

@bors
Copy link
Contributor

@bors bors commented on 942bed7 Oct 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging tomjakubowski/rust/rustdoc-ice-17736 = 942bed7 into auto

@bors
Copy link
Contributor

@bors bors commented on 942bed7 Oct 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tomjakubowski/rust/rustdoc-ice-17736 = 942bed7 merged ok, testing candidate = 3edcdbb

@bors
Copy link
Contributor

@bors bors commented on 942bed7 Oct 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 942bed7 Oct 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 3edcdbb

Please sign in to comment.