Skip to content

Commit

Permalink
Delete maud_htmlescape package (#311)
Browse files Browse the repository at this point in the history
Replace it with a symlink. Cargo will automatically resolve this to a
normal file on publish.
  • Loading branch information
lambda-fairy authored Nov 6, 2021
1 parent 45157fc commit 3232fb7
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 126 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[workspace]
members = [
"maud_htmlescape",
"maud_macros",
"maud",
]
Expand Down
2 changes: 0 additions & 2 deletions RELEASE_PROCESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
2. Update `Cargo.toml`:
- [`maud`](maud/Cargo.toml) (don't forget dependencies!)
- [`maud_macros`](maud_macros/Cargo.toml)
- [`maud_htmlescape`](maud_htmlescape/Cargo.toml) (if necessary)
3. Update `#![doc(html_root_html = "...")]`:
- [`maud`](maud/src/lib.rs)
- [`maud_macros`](maud_macros/src/lib.rs)
- [`maud_htmlescape`](maud_htmlescape/src/lib.rs) (if necessary)
4. `cd docs && cargo update`
5. Commit to a new branch `release-X.Y.Z`, open a PR, fix issues, merge
6. [Create a release](https://github.com/lambda-fairy/maud/releases/new)
Expand Down
105 changes: 79 additions & 26 deletions docs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion maud/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ default = []
actix-web = ["actix-web-dep", "futures-util"]

[dependencies]
maud_htmlescape = { version = "0.17.1", path = "../maud_htmlescape" }
maud_macros = { version = "0.22.3", path = "../maud_macros" }
iron = { version = ">= 0.5.1, < 0.7.0", optional = true }
rocket = { version = ">= 0.3, < 0.5", optional = true }
Expand Down
30 changes: 30 additions & 0 deletions maud/src/escape.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
extern crate alloc;

use alloc::string::String;

pub fn escape_to_string(input: &str, output: &mut String) {
for b in input.bytes() {
match b {
b'&' => output.push_str("&amp;"),
b'<' => output.push_str("&lt;"),
b'>' => output.push_str("&gt;"),
b'"' => output.push_str("&quot;"),
_ => unsafe { output.as_mut_vec().push(b) },
}
}
}

#[cfg(test)]
mod test {
extern crate alloc;

use super::escape_to_string;
use alloc::string::String;

#[test]
fn it_works() {
let mut s = String::new();
escape_to_string("<script>launchMissiles()</script>", &mut s);
assert_eq!(s, "&lt;script&gt;launchMissiles()&lt;/script&gt;");
}
}
45 changes: 41 additions & 4 deletions maud/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,46 @@ use core::fmt::{self, Write};

pub use maud_macros::{html, html_debug};

mod escape;

/// An adapter that escapes HTML special characters.
///
/// The following characters are escaped:
///
/// * `&` is escaped as `&amp;`
/// * `<` is escaped as `&lt;`
/// * `>` is escaped as `&gt;`
/// * `"` is escaped as `&quot;`
///
/// All other characters are passed through unchanged.
///
/// **Note:** In versions prior to 0.13, the single quote (`'`) was
/// escaped as well.
///
/// # Example
///
/// ```rust,ignore
/// use std::fmt::Write;
/// let mut s = String::new();
/// write!(Escaper::new(&mut s), "<script>launchMissiles()</script>").unwrap();
/// assert_eq!(s, "&lt;script&gt;launchMissiles()&lt;/script&gt;");
/// ```
pub struct Escaper<'a>(&'a mut String);

impl<'a> Escaper<'a> {
/// Creates an `Escaper` from a `String`.
pub fn new(buffer: &'a mut String) -> Escaper<'a> {
Escaper(buffer)
}
}

impl<'a> fmt::Write for Escaper<'a> {
fn write_str(&mut self, s: &str) -> fmt::Result {
escape::escape_to_string(s, self.0);
Ok(())
}
}

/// Represents a type that can be rendered as HTML.
///
/// If your type implements [`Display`][1], then it will implement this
Expand Down Expand Up @@ -93,10 +133,9 @@ impl<T: fmt::Display + ?Sized> Render for T {
/// [1]: https://github.com/dtolnay/case-studies/issues/14
#[doc(hidden)]
pub mod render {
use crate::Render;
use crate::{Escaper, Render};
use alloc::string::String;
use core::fmt::Write;
use maud_htmlescape::Escaper;

pub trait RenderInternal {
fn __maud_render_to(&self, w: &mut String);
Expand Down Expand Up @@ -145,8 +184,6 @@ impl<T: AsRef<str> + Into<String>> From<PreEscaped<T>> for String {
}
}

pub use maud_htmlescape::Escaper;

/// The literal string `<!DOCTYPE html>`.
///
/// # Example
Expand Down
14 changes: 0 additions & 14 deletions maud_htmlescape/Cargo.toml

This file was deleted.

Loading

0 comments on commit 3232fb7

Please sign in to comment.