Skip to content

Commit 26dd77f

Browse files
Fix hoedown error in rustdoc
1 parent 5a5a32a commit 26dd77f

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/librustdoc/html/markdown.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use std::ascii::AsciiExt;
3232
use std::cell::RefCell;
3333
use std::collections::{HashMap, VecDeque};
3434
use std::default::Default;
35-
use std::ffi::CString;
3635
use std::fmt::{self, Write};
3736
use std::str;
3837
use syntax::feature_gate::UnstableFeatures;
@@ -531,6 +530,7 @@ extern {
531530
fn hoedown_buffer_new(unit: libc::size_t) -> *mut hoedown_buffer;
532531
fn hoedown_buffer_puts(b: *mut hoedown_buffer, c: *const libc::c_char);
533532
fn hoedown_buffer_free(b: *mut hoedown_buffer);
533+
fn hoedown_buffer_put(b: *mut hoedown_buffer, c: *const libc::c_char, len: libc::size_t);
534534
}
535535

536536
impl hoedown_buffer {
@@ -620,8 +620,7 @@ pub fn render(w: &mut fmt::Formatter,
620620
Some("rust-example-rendered"),
621621
None,
622622
playground_button.as_ref().map(String::as_str)));
623-
let output = CString::new(s).unwrap();
624-
hoedown_buffer_puts(ob, output.as_ptr());
623+
hoedown_buffer_put(ob, s.as_ptr() as *const libc::c_char, s.len());
625624
})
626625
}
627626
}
@@ -681,8 +680,7 @@ pub fn render(w: &mut fmt::Formatter,
681680
<a href='#{id}'>{sec}{}</a></h{lvl}>",
682681
s, lvl = level, id = id, sec = sec);
683682

684-
let text = CString::new(text).unwrap();
685-
unsafe { hoedown_buffer_puts(ob, text.as_ptr()) }
683+
unsafe { hoedown_buffer_put(ob, text.as_ptr() as *const libc::c_char, text.len()); }
686684
}
687685

688686
extern fn codespan(
@@ -699,9 +697,10 @@ pub fn render(w: &mut fmt::Formatter,
699697
collapse_whitespace(s)
700698
};
701699

702-
let content = format!("<code>{}</code>", Escape(&content));
703-
let element = CString::new(content).unwrap();
704-
unsafe { hoedown_buffer_puts(ob, element.as_ptr()); }
700+
let content = format!("<code>{}</code>", Escape(&content)).replace("\0", "\\0");
701+
unsafe {
702+
hoedown_buffer_put(ob, content.as_ptr() as *const libc::c_char, content.len());
703+
}
705704
// Return anything except 0, which would mean "also print the code span verbatim".
706705
1
707706
}

src/test/rustdoc/nul-error.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// build-aux-docs
12+
// ignore-cross-compile
13+
14+
#![crate_name = "foo"]
15+
16+
// @has foo/fn.foo.html '//code' '0'
17+
#[doc = "Attempted to pass a string containing `\0`"]
18+
pub fn foo() {}

0 commit comments

Comments
 (0)