From ae98f4cac55af394c3e6477ed4c366f63b6626aa Mon Sep 17 00:00:00 2001 From: Oliver Middleton Date: Mon, 29 Jan 2018 16:44:35 +0000 Subject: [PATCH] rustdoc: Fix link title rendering with hoedown The link title needs to be HTML escaped. --- src/librustdoc/html/markdown.rs | 2 +- src/test/rustdoc/link-title-escape.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc/link-title-escape.rs diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index dce0c4b001a0d..82ced00644da8 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -872,7 +872,7 @@ pub fn render(w: &mut fmt::Formatter, let link_out = format!("{content}", link = link_buf, title = title.map_or(String::new(), - |t| format!(" title=\"{}\"", t)), + |t| format!(" title=\"{}\"", Escape(&t))), content = content.unwrap_or(String::new())); unsafe { hoedown_buffer_put(ob, link_out.as_ptr(), link_out.len()); } diff --git a/src/test/rustdoc/link-title-escape.rs b/src/test/rustdoc/link-title-escape.rs new file mode 100644 index 0000000000000..eb53c3c2cb52d --- /dev/null +++ b/src/test/rustdoc/link-title-escape.rs @@ -0,0 +1,19 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: -Z unstable-options --disable-commonmark + +#![crate_name = "foo"] + +//! hello [foo] +//! +//! [foo]: url 'title & & "things"' + +// @has 'foo/index.html' 'title & <stuff> & "things"'