Skip to content

Commit

Permalink
Enforce safety and lintiness
Browse files Browse the repository at this point in the history
Also update the README, dependencies list, and required Rust version.
  • Loading branch information
notriddle committed Feb 14, 2019
1 parent 885c7d7 commit bf894f2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cache: cargo
rust:
- beta
- stable
- 1.24.0
- 1.30.0

branches:
only:
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Unreleased

*
* Bump minimum supported Rust version to 1.30.

# 2.0.0

Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords = [ "sanitization", "html", "security", "xss" ]
license = "MIT / Apache-2.0"
readme = "README.md"
documentation = "https://docs.rs/ammonia/"
repository = "https://github.com/notriddle/ammonia"
repository = "https://github.com/rust-ammonia/ammonia"
categories = [ "web-programming", "text-processing" ]

[dependencies]
Expand All @@ -16,7 +16,7 @@ maplit = "1.0"
matches = "0.1.6"
tendril = "0.4"
url = "1"
lazy_static = "1"
lazy_static = "1.2"

[dev-dependencies]
version-sync = "0.6"
version-sync = "0.7"
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ HTML Sanitization
=================

[![Crates.IO](https://img.shields.io/crates/v/ammonia.svg)](https://crates.rs/crates/ammonia)
![Requires rustc 1.24.0](https://img.shields.io/badge/rustc-1.24.0+-green.svg)

Chat: [Gitter], [Matrix]

[Gitter]: https://gitter.im/rust-ammonia/Lobby
[Matrix]: https://matrix.to/#/#rust-ammonia:gpmatrix.com
![Requires rustc 1.30.0](https://img.shields.io/badge/rustc-1.30.0+-green.svg)

Ammonia is a whitelist-based HTML sanitization library. It is designed to
prevent cross-site scripting, layout breaking, and clickjacking caused
Expand Down
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (C) Michael Howell and others
// this library is released under the same terms as Rust itself.

#![forbid(unsafe_code)]
#![forbid(missing_docs)]

//! Ammonia is a whitelist-based HTML sanitization library. It is designed to
//! prevent cross-site scripting, layout breaking, and clickjacking caused
//! by untrusted user-provided HTML being mixed into a larger web page.
Expand Down Expand Up @@ -1648,7 +1651,15 @@ impl fmt::Debug for UrlRelative {
}
}

/// Types that implement this trait can be used to convert a relative URL into an absolute URL.
///
/// This evaluator is only called when the URL is relative; absolute URLs are not evaluated.
///
/// See [`url_relative`][url_relative] for more details.
///
/// [url_relative]: struct.Builder.html#method.url_relative
pub trait UrlRelativeEvaluate: Send + Sync {
/// Return `None` to remove the attribute. Return `Some(str)` to replace it with a new string.
fn evaluate<'a>(&self, &'a str) -> Option<Cow<'a, str>>;
}
impl<T> UrlRelativeEvaluate for T where T: Fn(&str) -> Option<Cow<str>> + Send + Sync {
Expand All @@ -1663,7 +1674,13 @@ impl fmt::Debug for AttributeFilter {
}
}

/// Types that implement this trait can be used to remove or rewrite arbitrary attributes.
///
/// See [`attribute_filter`][attribute_filter] for more details.
///
/// [attribute_filter]: struct.Builder.html#method.attribute_filter
pub trait AttributeFilter: Send + Sync {
/// Return `None` to remove the attribute. Return `Some(str)` to replace it with a new string.
fn filter<'a>(&self, &str, &str, &'a str) -> Option<Cow<'a, str>>;
}

Expand All @@ -1672,6 +1689,7 @@ impl<T> AttributeFilter for T where T: for<'a> Fn(&str, &str, &'a str) -> Option
self(element, attribute, value)
}
}

/// A sanitized HTML document.
///
/// The `Document` type is an opaque struct representing an HTML fragment that was sanitized by
Expand Down

0 comments on commit bf894f2

Please sign in to comment.