Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic when using format! and debug output for a nested value with a bad escape character in the LazyReader. #770

Open
jpschorr opened this issue May 16, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jpschorr
Copy link
Contributor

#[test]
fn blow_up() {
    // At the top level, the bad escape character causes an error before I can try to debug format anything
    let bad_str = r#" "[1-9]\d+" "#;

    let mut reader = LazyReader::new(bad_str.as_bytes());
    let val: LazyValue<AnyEncoding> = reader.next().unwrap().unwrap();
    let read = val.read();
    // the bad string causes the `read` to error
    assert!(read.is_err());

    // If I nest the bad string, I can get `format!("Blows up: {read:?}")` to panic
    let bad = format!(r#"{{ nested: {bad_str} }}"#);

    let mut reader = LazyReader::new(bad.as_bytes());
    let val: LazyValue<AnyEncoding> = reader.next().unwrap().unwrap();
    let read = val.read();
    // nesting the bad string causes the `read` to ok
    assert!(read.is_ok());
    let read = read.unwrap();

    // dbg! works
    dbg!(&read);
    // But formating with `:?` causes a panic:
    //       a formatting trait implementation returned an error: Error
    format!("Blows up: {read:?}");
}

The panic is in std::fmt::format: https://doc.rust-lang.org/src/alloc/fmt.rs.html#633

@jpschorr jpschorr added the bug Something isn't working label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant