use twiml_rust::xml_escape::{escape_xml_attr, escape_xml_text};
#[test]
fn test_escape_xml_text_basic() {
assert_eq!(escape_xml_text("Hello World"), "Hello World");
}
#[test]
fn test_escape_xml_text_ampersand() {
assert_eq!(escape_xml_text("Tom & Jerry"), "Tom & Jerry");
}
#[test]
fn test_escape_xml_text_less_than() {
assert_eq!(escape_xml_text("5 < 10"), "5 < 10");
}
#[test]
fn test_escape_xml_text_greater_than() {
assert_eq!(escape_xml_text("10 > 5"), "10 > 5");
}
#[test]
fn test_escape_xml_text_tags() {
assert_eq!(
escape_xml_text("<script>alert('xss')</script>"),
"<script>alert('xss')</script>"
);
}
#[test]
fn test_escape_xml_text_multiple() {
assert_eq!(escape_xml_text("A & B < C > D"), "A & B < C > D");
}
#[test]
fn test_escape_xml_text_injection_attempt() {
assert_eq!(
escape_xml_text("Hello</Body><Message to=\"+1-attacker\"><Body>Hacked"),
"Hello</Body><Message to=\"+1-attacker\"><Body>Hacked"
);
}
#[test]
fn test_escape_xml_attr_basic() {
assert_eq!(escape_xml_attr("Hello World"), "Hello World");
}
#[test]
fn test_escape_xml_attr_double_quotes() {
assert_eq!(escape_xml_attr("Say \"Hello\""), "Say "Hello"");
}
#[test]
fn test_escape_xml_attr_single_quotes() {
assert_eq!(escape_xml_attr("It's fine"), "It's fine");
}
#[test]
fn test_escape_xml_attr_all_special_chars() {
assert_eq!(escape_xml_attr("&<>\"'"), "&<>"'");
}
#[test]
fn test_escape_xml_attr_injection_attempt() {
assert_eq!(
escape_xml_attr("\" onload=\"alert('xss')"),
"" onload="alert('xss')"
);
}
#[test]
fn test_escape_xml_attr_url_with_params() {
assert_eq!(
escape_xml_attr("https://example.com?a=1&b=2"),
"https://example.com?a=1&b=2"
);
}