pub fn space_variants(input: &str) -> StringExpand description
Replaces regular spaces with various Unicode space characters.
Substitutes ASCII space characters (U+0020) with random Unicode space variants including non-breaking space (U+00A0) and various em/en spaces. These look identical but have different codepoints, useful for testing whitespace normalization and parser robustness.
§Use Cases
- WAF Bypass: Evade filters that only check for ASCII spaces
- Blue Team: Test whitespace normalization in parsers
- Input Validation: Verify proper handling of Unicode spaces
- SQL Injection: Use non-breaking spaces to bypass filters
§Examples
use redstr::space_variants;
let result = space_variants("hello world");
// Looks identical: "hello world"
// But may contain U+00A0, U+2000, U+2001, etc. instead of U+0020
assert_eq!(result.chars().filter(|c| c.is_whitespace()).count(), 1);
// SQL injection with Unicode spaces
let sql = space_variants("SELECT * FROM users");
// Uses non-breaking spaces to bypass filters
// Test whitespace normalization
let text = space_variants("word1 word2 word3");
// Visually identical but with mixed Unicode spaces