Skip to content

Commit dcf0218

Browse files
committed
Auto merge of #1876 - AZanellato:ammonia-3.0-upgrade, r=smarnach
Ammonia 3.0 upgrade Closes #1872. I have followed the instructions on the issue. Basically removing that list of allowed elements and relying on ammonia to do the job and also upgrading ammonia to 3.0.
2 parents 43619db + 6df0cfd commit dcf0218

File tree

3 files changed

+82
-65
lines changed

3 files changed

+82
-65
lines changed

Cargo.lock

Lines changed: 77 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ serde_json = "1.0.0"
5353
serde = { version = "1.0.0", features = ["derive"] }
5454
chrono = { version = "0.4.0", features = ["serde"] }
5555
comrak = { version = "0.4.0", default-features = false }
56-
ammonia = "2.0.0"
56+
ammonia = "3.0.0"
5757
docopt = "1.0"
5858
scheduled-thread-pool = "0.2.0"
5959
derive_deref = "1.0.0"

src/render.rs

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -22,54 +22,6 @@ impl<'a> MarkdownRenderer<'a> {
2222
/// Per `readme_to_html`, `base_url` is the base URL prepended to any
2323
/// relative links in the input document. See that function for more detail.
2424
fn new(base_url: Option<&'a str>) -> MarkdownRenderer<'a> {
25-
let tags = hashset(&[
26-
"a",
27-
"b",
28-
"blockquote",
29-
"br",
30-
"code",
31-
"dd",
32-
"del",
33-
"dl",
34-
"dt",
35-
"em",
36-
"h1",
37-
"h2",
38-
"h3",
39-
"h4",
40-
"h5",
41-
"h6",
42-
"hr",
43-
"i",
44-
"img",
45-
"input",
46-
"kbd",
47-
"li",
48-
"ol",
49-
"p",
50-
"pre",
51-
"s",
52-
"strike",
53-
"strong",
54-
"sub",
55-
"sup",
56-
"table",
57-
"tbody",
58-
"td",
59-
"th",
60-
"thead",
61-
"tr",
62-
"ul",
63-
"hr",
64-
"span",
65-
]);
66-
let tag_attributes = hashmap(&[
67-
("a", hashset(&["href", "id", "target"])),
68-
("img", hashset(&["width", "height", "src", "alt", "align"])),
69-
("input", hashset(&["checked", "disabled", "type"])),
70-
("th", hashset(&["rowspan", "colspan"])),
71-
("td", hashset(&["rowspan", "colspan"])),
72-
]);
7325
let allowed_classes = hashmap(&[(
7426
"code",
7527
hashset(&[
@@ -91,11 +43,12 @@ impl<'a> MarkdownRenderer<'a> {
9143
)]);
9244
let sanitize_url = UrlRelative::Custom(Box::new(SanitizeUrl::new(base_url)));
9345

94-
let mut html_sanitizer = Builder::new();
46+
let mut html_sanitizer = Builder::default();
9547
html_sanitizer
48+
.add_tags(&["input"])
9649
.link_rel(Some("nofollow noopener noreferrer"))
97-
.tags(tags)
98-
.tag_attributes(tag_attributes)
50+
.add_tag_attributes("a", &["id", "target"])
51+
.add_tag_attributes("input", &["checked", "disabled", "type"])
9952
.allowed_classes(allowed_classes)
10053
.url_relative(sanitize_url)
10154
.id_prefix(Some("user-content-"));

0 commit comments

Comments
 (0)