-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Fix rustdoc #43691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix rustdoc #43691
Conversation
24d058f
to
d662c1a
Compare
src/librustdoc/html/markdown.rs
Outdated
} | ||
if !added { | ||
full.extend_from_slice(&[b'\\', b'0']); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop feels suspect. After a long enough read it seems okay, but maybe replacing it with a loop over indices and something like full.splice(idx..(idx+1), b"\\0".iter().cloned())
would make it easier to read its intent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth s.replace("\0", "\\0")
would be even easier to read.
This isn't how I would fix this. I don't think there is any need to escape null bytes as they are valid UTF-8. The issue is with the Specifically replacing all 3 instances of: let element = CString::new(content).unwrap();
unsafe { hoedown_buffer_puts(ob, element.as_ptr()); } with: unsafe { hoedown_buffer_put(ob, content.as_ptr(), content.len()); } |
@GuillaumeGomez the only reason I wouldn't fix this issue this way is because there's an unexpected side effect: now writing |
The problem only exists because of |
d662c1a
to
26dd77f
Compare
Updated, and keep in mind that this "fix" only concerns hoedown and won't be an issue with pulldown. |
src/librustdoc/html/markdown.rs
Outdated
@@ -531,6 +530,7 @@ extern { | |||
fn hoedown_buffer_new(unit: libc::size_t) -> *mut hoedown_buffer; | |||
fn hoedown_buffer_puts(b: *mut hoedown_buffer, c: *const libc::c_char); | |||
fn hoedown_buffer_free(b: *mut hoedown_buffer); | |||
fn hoedown_buffer_put(b: *mut hoedown_buffer, c: *const libc::c_char, len: libc::size_t); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second parameter is const uint8_t *data
so here it should be *const u8
. That also means as *const libc::c_char
can be removed from below.
src/librustdoc/html/markdown.rs
Outdated
let content = format!("<code>{}</code>", Escape(&content)); | ||
let element = CString::new(content).unwrap(); | ||
unsafe { hoedown_buffer_puts(ob, element.as_ptr()); } | ||
let content = format!("<code>{}</code>", Escape(&content)).replace("\0", "\\0"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change seems unnecessary. As hoedown just passes null bytes through unmodified everywhere else there is no reason to escape it in this one case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't do it, it doesn't appear in the generated HTML.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will, but browsers may not show anything but that's expected and what already happens if null bytes appear in normal paragraphs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So be it.
Updated. No more |
cf80e67
to
d0916c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR seems fine, but I'm still not super mega confident with rustdoc's codebase
src/librustdoc/html/markdown.rs
Outdated
@@ -531,6 +530,7 @@ extern { | |||
fn hoedown_buffer_new(unit: libc::size_t) -> *mut hoedown_buffer; | |||
fn hoedown_buffer_puts(b: *mut hoedown_buffer, c: *const libc::c_char); | |||
fn hoedown_buffer_free(b: *mut hoedown_buffer); | |||
fn hoedown_buffer_put(b: *mut hoedown_buffer, c: *const u8, len: libc::size_t); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is hoedown_buffer_puts
used elsewhere? This PR seems mostly to be replacing puts with put. If puts isn't, then we should also remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's still used.
r=me if @QuietMisdreavus likes it too |
r=me pending travis on this last push |
@bors r+ |
📌 Commit ec0ca3a has been approved by |
Fix rustdoc Fixes #43625. r? @rust-lang/dev-tools cc @rust-lang/docs
☀️ Test successful - status-appveyor, status-travis |
Fixes #43625.
r? @rust-lang/dev-tools
cc @rust-lang/docs