#![forbid(unsafe_code)]
pub mod css;
pub mod display;
pub mod html;
pub mod javascript;
pub mod json;
pub mod rust;
pub mod sql;
pub mod uri;
pub mod xml;
mod engine;
pub use css::{for_css_string, for_css_url, write_css_string, write_css_url};
pub use display::{
display_cdata, display_css_string, display_css_url, display_form_urlencoded, display_html,
display_html_attribute, display_html_content, display_html_unquoted_attribute,
display_javascript, display_javascript_attribute, display_javascript_block,
display_javascript_source, display_js_template, display_json, display_rust_byte_string,
display_rust_char, display_rust_string, display_sql, display_sql_backslash,
display_uri_component, display_uri_path, display_xml, display_xml11, display_xml11_attribute,
display_xml11_content, display_xml_attribute, display_xml_comment, display_xml_content,
};
pub use html::{
for_html, for_html_attribute, for_html_content, for_html_unquoted_attribute, write_html,
write_html_attribute, write_html_content, write_html_unquoted_attribute,
};
pub use javascript::{
for_javascript, for_javascript_attribute, for_javascript_block, for_javascript_source,
for_js_template, write_javascript, write_javascript_attribute, write_javascript_block,
write_javascript_source, write_js_template,
};
pub use json::{for_json, write_json};
pub use rust::{
for_rust_byte_string, for_rust_char, for_rust_string, write_rust_byte_string, write_rust_char,
write_rust_string,
};
pub use sql::{for_sql, for_sql_backslash, write_sql, write_sql_backslash};
pub use uri::{
for_form_urlencoded, for_uri_component, for_uri_path, write_form_urlencoded,
write_uri_component, write_uri_path,
};
pub use xml::{
for_cdata, for_xml, for_xml11, for_xml11_attribute, for_xml11_content, for_xml_attribute,
for_xml_comment, for_xml_content, write_cdata, write_xml, write_xml11, write_xml11_attribute,
write_xml11_content, write_xml_attribute, write_xml_comment, write_xml_content,
};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn empty_string_returns_empty() {
assert_eq!(for_html(""), "");
assert_eq!(for_html_content(""), "");
assert_eq!(for_html_attribute(""), "");
assert_eq!(for_html_unquoted_attribute(""), "");
assert_eq!(for_javascript(""), "");
assert_eq!(for_javascript_attribute(""), "");
assert_eq!(for_javascript_block(""), "");
assert_eq!(for_javascript_source(""), "");
assert_eq!(for_css_string(""), "");
assert_eq!(for_css_url(""), "");
assert_eq!(for_uri_component(""), "");
assert_eq!(for_uri_path(""), "");
assert_eq!(for_xml(""), "");
assert_eq!(for_xml_content(""), "");
assert_eq!(for_xml_attribute(""), "");
assert_eq!(for_xml_comment(""), "");
assert_eq!(for_cdata(""), "");
assert_eq!(for_xml11(""), "");
assert_eq!(for_xml11_content(""), "");
assert_eq!(for_xml11_attribute(""), "");
assert_eq!(for_json(""), "");
assert_eq!(for_rust_string(""), "");
assert_eq!(for_rust_char(""), "");
assert_eq!(for_rust_byte_string(""), "");
assert_eq!(for_js_template(""), "");
assert_eq!(for_sql(""), "");
assert_eq!(for_sql_backslash(""), "");
assert_eq!(for_form_urlencoded(""), "");
}
#[test]
fn empty_string_writer_variants() {
let mut buf = String::new();
write_html(&mut buf, "").unwrap();
assert_eq!(buf, "");
buf.clear();
write_javascript(&mut buf, "").unwrap();
assert_eq!(buf, "");
buf.clear();
write_css_string(&mut buf, "").unwrap();
assert_eq!(buf, "");
buf.clear();
write_uri_component(&mut buf, "").unwrap();
assert_eq!(buf, "");
buf.clear();
write_uri_path(&mut buf, "").unwrap();
assert_eq!(buf, "");
buf.clear();
write_form_urlencoded(&mut buf, "").unwrap();
assert_eq!(buf, "");
}
#[test]
fn multibyte_utf8_html() {
assert_eq!(for_html("café"), "café");
assert_eq!(for_html("世界"), "世界");
assert_eq!(for_html("😀"), "😀");
assert_eq!(for_html("é<世>&😀"), "é<世>&😀");
}
#[test]
fn multibyte_utf8_javascript() {
assert_eq!(for_javascript("café"), "café");
assert_eq!(for_javascript("世界"), "世界");
assert_eq!(for_javascript("😀"), "😀");
}
#[test]
fn multibyte_utf8_css_string() {
assert_eq!(for_css_string("café"), "café");
assert_eq!(for_css_string("世界"), "世界");
assert_eq!(for_css_string("😀"), "😀");
}
#[test]
fn multibyte_utf8_uri_component() {
assert_eq!(for_uri_component("é"), "%C3%A9");
assert_eq!(for_uri_component("世"), "%E4%B8%96");
assert_eq!(for_uri_component("😀"), "%F0%9F%98%80");
assert_eq!(for_uri_component("café"), "caf%C3%A9");
}
#[test]
fn multibyte_utf8_uri_path() {
assert_eq!(for_uri_path("é"), "%C3%A9");
assert_eq!(for_uri_path("世"), "%E4%B8%96");
assert_eq!(for_uri_path("😀"), "%F0%9F%98%80");
assert_eq!(for_uri_path("/café"), "/caf%C3%A9");
}
#[test]
fn multibyte_utf8_form_urlencoded() {
assert_eq!(for_form_urlencoded("é"), "%C3%A9");
assert_eq!(for_form_urlencoded("世"), "%E4%B8%96");
assert_eq!(for_form_urlencoded("😀"), "%F0%9F%98%80");
assert_eq!(for_form_urlencoded("café"), "caf%C3%A9");
}
#[test]
fn multibyte_utf8_rust_byte_string() {
assert_eq!(for_rust_byte_string("é"), r"\xc3\xa9");
assert_eq!(for_rust_byte_string("世"), r"\xe4\xb8\x96");
assert_eq!(for_rust_byte_string("😀"), r"\xf0\x9f\x98\x80");
}
#[test]
fn multibyte_utf8_rust_string_passthrough() {
assert_eq!(for_rust_string("café"), "café");
assert_eq!(for_rust_string("世界"), "世界");
assert_eq!(for_rust_string("😀"), "😀");
}
#[test]
fn multibyte_utf8_json() {
assert_eq!(for_json("café"), "café");
assert_eq!(for_json("世界"), "世界");
assert_eq!(for_json("😀"), "😀");
}
#[test]
fn multibyte_utf8_sql() {
assert_eq!(for_sql("café"), "café");
assert_eq!(for_sql("世界"), "世界");
assert_eq!(for_sql("😀"), "😀");
}
#[test]
fn multibyte_utf8_sql_backslash() {
assert_eq!(for_sql_backslash("café"), "café");
assert_eq!(for_sql_backslash("世界"), "世界");
assert_eq!(for_sql_backslash("😀"), "😀");
}
#[test]
fn multibyte_utf8_xml() {
assert_eq!(for_xml("café"), "café");
assert_eq!(for_xml("世界"), "世界");
assert_eq!(for_xml("😀"), "😀");
}
}