Skip to content

Commit 827ff65

Browse files
committed
Sanitize rendered html with ammonia
1 parent 501cef8 commit 827ff65

File tree

4 files changed

+167
-1
lines changed

4 files changed

+167
-1
lines changed

Cargo.lock

Lines changed: 159 additions & 0 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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ serde = "1.0.0"
5050
clippy = { version = "=0.0.142", optional = true }
5151
chrono = "0.4.0"
5252
pulldown-cmark = { version = "0.0.15", default-features = false }
53+
ammonia = "0.5.0"
5354

5455
conduit = "0.8"
5556
conduit-conditional-get = "0.8"

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extern crate log;
1717
extern crate serde_json;
1818
#[macro_use]
1919
extern crate serde_derive;
20+
extern crate ammonia;
2021
extern crate chrono;
2122
extern crate curl;
2223
extern crate diesel_full_text_search;

src/render.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
use ammonia::Ammonia;
12
use pulldown_cmark::Parser;
23
use pulldown_cmark::html;
34

45
use util::CargoResult;
56

67
pub fn markdown_to_html(text: &str) -> CargoResult<String> {
78
let mut rendered = String::with_capacity(text.len() * 3 / 2);
9+
let cleaner = Ammonia {
10+
keep_cleaned_elements: true,
11+
..Ammonia::default()
12+
};
813
let parser = Parser::new(text);
914
html::push_html(&mut rendered, parser);
10-
Ok(rendered)
15+
Ok(cleaner.clean(&rendered))
1116
}

0 commit comments

Comments
 (0)