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

Total sort order for redactions #587

Open
mitsuhiko opened this issue Sep 6, 2024 · 3 comments
Open

Total sort order for redactions #587

mitsuhiko opened this issue Sep 6, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@mitsuhiko
Copy link
Owner

Followup to #586 there is another case in the redaction code that is most likely also wrong. It pairs sort_by with unwrap_or.

@max-sixty
Copy link
Collaborator

max-sixty commented Sep 7, 2024

From this code?

#[cfg_attr(docsrs, doc(cfg(feature = "redactions")))]
pub fn sorted_redaction() -> Redaction {
    fn sort(mut value: Content, _path: ContentPath) -> Content {
        match value.resolve_inner_mut() {
            Content::Seq(ref mut val) => {
                val.sort_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal))
            }
            Content::Map(ref mut val) => {
                val.sort_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal))
            }
            Content::Struct(_, ref mut fields)
            | Content::StructVariant(_, _, _, ref mut fields) => {
                fields.sort_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal))
            }
            _ => {}
        }
        value
    }
    dynamic_redaction(sort)
}

I don't feel confident here, but what's the case for this not being a total order? That a.partial_cmp(b) is different from b.partial_cmp(a)? I would have thought it's fine that things are occasionally not comparable and treated as equal...

@mitsuhiko
Copy link
Owner Author

It would be for floats containing NaNs in vectors.

@max-sixty
Copy link
Collaborator

max-sixty commented Sep 7, 2024

OK, I had thought those consistently evaluate to Equal given .unwrap_or(std::cmp::Ordering::Equal), but I'm surely missing something

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

2 participants