tail-fin-common 0.3.0

Shared infrastructure for tail-fin: error types, page_fetch, cookies, CDP helpers
Documentation
/// Escape a string for safe embedding in JavaScript template literals.
pub fn escape_js_string(s: &str) -> String {
    s.replace('\\', "\\\\")
        .replace('"', "\\\"")
        .replace('\n', "\\n")
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_escape_basic() {
        assert_eq!(escape_js_string("hello"), "hello");
    }

    #[test]
    fn test_escape_quotes() {
        assert_eq!(escape_js_string(r#"say "hi""#), r#"say \"hi\""#);
    }

    #[test]
    fn test_escape_newline() {
        assert_eq!(escape_js_string("line1\nline2"), "line1\\nline2");
    }

    #[test]
    fn test_escape_backslash() {
        assert_eq!(escape_js_string("a\\b"), "a\\\\b");
    }
}