| 1 |
use std::sync::Arc; |
| 2 |
|
| 3 |
use super::*; |
| 4 |
|
| 5 |
#[test] |
| 6 |
fn image_url_rewriter() { |
| 7 |
html_opts_i( |
| 8 |
"", |
| 9 |
"<p><img src=\"https://safe.example.com?url=http://unsafe.example.com/bad.png\" alt=\"\" /></p>\n", |
| 10 |
true, |
| 11 |
|opts| { |
| 12 |
opts.extension.image_url_rewriter = Some(Arc::new(|url: &str| { |
| 13 |
format!("{}{}", "https://safe.example.com?url=", url) |
| 14 |
})) |
| 15 |
}, |
| 16 |
); |
| 17 |
} |
| 18 |
|
| 19 |
#[test] |
| 20 |
fn link_url_rewriter() { |
| 21 |
html_opts_i( |
| 22 |
"[my link](http://unsafe.example.com/bad)", |
| 23 |
"<p><a href=\"https://safe.example.com/norefer?url=http://unsafe.example.com/bad\">my link</a></p>\n", |
| 24 |
true, |
| 25 |
|opts| { |
| 26 |
opts.extension.link_url_rewriter = Some(Arc::new(|url: &str| { |
| 27 |
format!("{}{}", "https://safe.example.com/norefer?url=", url) |
| 28 |
})) |
| 29 |
}, |
| 30 |
); |
| 31 |
} |
| 32 |
|
| 33 |
#[test] |
| 34 |
fn can_borrow_from_context() { |
| 35 |
let rewrite_to = "http://example.org"; |
| 36 |
|
| 37 |
html_opts_i( |
| 38 |
"[my link](http://example.com/)", |
| 39 |
"<p><a href=\"http://example.org\">my link</a></p>\n", |
| 40 |
true, |
| 41 |
|opts| opts.extension.link_url_rewriter = Some(Arc::new(|_: &str| rewrite_to.to_owned())), |
| 42 |
); |
| 43 |
} |