Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/bbcode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,21 @@ mod tests {
use super::parse;

assert_eq!("&lt;b&gt;Test&lt;/b&gt;", parse("<b>Test</b>"));
assert_eq!("[xxx&lt;iframe&gt;]Test[/xxx&lt;iframe&gt;]", parse("[xxx<iframe>]Test[/xxx<iframe>]"));
assert_eq!("[url=javascript:alert(String.fromCharCode(88,83,83))]https://zombo.com[/url]", parse("[url=javascript:alert(String.fromCharCode(88,83,83))]https://zombo.com[/url]"))
assert_eq!(
"[xxx&lt;iframe&gt;]Test[/xxx&lt;iframe&gt;]",
parse("[xxx<iframe>]Test[/xxx<iframe>]")
);
assert_eq!(
"[url=javascript:alert(String.fromCharCode(88,83,83))]https://zombo.com[/url]",
parse("[url=javascript:alert(String.fromCharCode(88,83,83))]https://zombo.com[/url]")
);

assert_eq!("<a class=\"bbCode tagUrl\" ref=\"nofollow\" href=\"http://exa&quot;mple.com/\">test</a>", parse("[url=http://exa\"mple.com]test[/url]"));
assert_eq!("<a class=\"bbCode tagUrl\" ref=\"nofollow\" href=\"http://exa&quot;mple.com/\">test</a>", parse("[url=http://exa%22mple.com]test[/url]"));
assert_eq!("<a class=\"bbCode tagUrl\" ref=\"nofollow\" href=\"http://exa&quot;mple.com/\">http://exa%22mple.com</a>", parse("[url]http://exa%22mple.com[/url]"));
assert_eq!(
"<img src=\"http://exa&quot;mple.com/\" />",
parse("[img]http://exa%22mple.com[/img]")
);
}
}
8 changes: 6 additions & 2 deletions src/bbcode/tag/embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl super::Tag {
match url.scheme() {
"http" | "https" => {
el.clear_contents();
return format!("<img src=\"{}\" />", url.as_str());
return format!("<img src=\"{}\" />", sanitize_url_for_attribute(&url));
}
_ => {}
}
Expand Down Expand Up @@ -54,7 +54,7 @@ impl super::Tag {
match url {
Some(url) => format!(
"<a class=\"bbCode tagUrl\" ref=\"nofollow\" href=\"{}\">{}",
url.as_str(),
sanitize_url_for_attribute(&url),
contents
),
// If we have no content, we are broken.
Expand All @@ -78,3 +78,7 @@ fn url_arg(input: &str) -> Option<Result<Url, &str>> {
Err(_) => None,
}
}

fn sanitize_url_for_attribute(url: &Url) -> String {
url.as_str().replace("\"", "&quot;")
}