Skip to content

#[pg_test(expected = ...)] corrupts raw-string literals and panics on malformed input #2316

Description

@isdaniel

Summary

The #[pg_test] attribute parses its expected = "..." argument with a hand-rolled TokenTree walker instead of syn. This causes bug:

Raw-string corruption — expected values written as raw strings (needed whenever the expected Postgres error message contains a ") are silently mangled, so the test never matches the real error.

pre-prepare

/// Raises an error whose message contains a literal double-quote: foo "bar"
#[pg_extern]
fn raise_quoted_error() -> &'static str {
    error!(r#"foo "bar""#);
}

Bug — raw-string corruption

#[pg_test(error = r#"foo "bar""#)]
fn bug1_raw_string_expected_is_corrupted() {
	Spi::get_one::<&str>("SELECT raise_quoted_error()").unwrap();
}

Result:

Client Error:
foo "bar"
postgres location: lib.rs:8
rust location: <unknown>


note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
    tests::pg_bug1_raw_string_expected_is_corrupted

The real error message from raise_quoted_error() is foo "bar", so the test fails with a mismatch even though the author wrote the correct expected string.

Environment

  • pgrx: 0.18.1
  • OS: Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions