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

Redaction order seems to matter when using sorted_redaction #683

Open
Threated opened this issue Nov 10, 2024 · 0 comments
Open

Redaction order seems to matter when using sorted_redaction #683

Threated opened this issue Nov 10, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Threated
Copy link

Threated commented Nov 10, 2024

What happened?

When using the sorted_redaction it seems to be important to place the sorting redactions at the end which I did not expect to matter. Also using [] as the selector instead of . also seems to fix the issue in the example below but does not seem to work if the redacted key value pair is nested somewhere deeper.

Reproduction steps

// insta = { version = "1.41.1", features = ["json", "redactions"] }
// rand = "*"
// serde_json = "*"
#[test]
fn insta_sorting_bug() {
    use insta::assert_json_snapshot;
    use rand::random;
    use serde_json::json;

    let json = json!([
        {
            "a": random::<bool>(),
            "z": 1,
        },
        {
            "a": random::<bool>(),
            "z": 2,
        }
    ]);
    // Inconsistent
    assert_json_snapshot!(json, {
        "." => insta::sorted_redaction(),
        "[].a" =>  "[redacted]",
    });
    // Consistent
    // assert_json_snapshot!(json, {
    //     "[].a" =>  "[redacted]",
    //     "." => insta::sorted_redaction(),
    // });
    // Consistent for this case but not for more deeply nested redacted values
    // assert_json_snapshot!(json, {
    //     "[]" => insta::sorted_redaction(),
    //     "[].a" =>  "[redacted]",
    // });
}

Insta Version

1.41.1

rustc Version

1.81

What did you expect?

Redaction order to not be important or its importance mentioned in the docs of sorted_redaction.

@Threated Threated added the bug Something isn't working label Nov 10, 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