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

Fail to validate nested array #218

Closed
gregorydemay opened this issue Feb 13, 2024 · 4 comments
Closed

Fail to validate nested array #218

gregorydemay opened this issue Feb 13, 2024 · 4 comments
Assignees
Labels
bug Something isn't working cbor json validation
Milestone

Comments

@gregorydemay
Copy link

  1. Tested with cddl = "0.9.4"
  2. Cannot handle a CDDL schema involving nested array, e.g., [0, [0]]. Note that the not-nested schema [0, 0] seems to work fine.

Example

    #[test]
    fn should_validate_nested_array() {
        let schema = r#"root = [0, 0]"#;
        let cbor_bytes = [0x82, 0x00, 0x00];
        let result = cddl::validate_cbor_from_slice(schema, &cbor_bytes, None);
        assert!( //PASSES!
            result.is_ok(),
            "Validation of {:x?} failed: {:?}",
            cbor_bytes,
            result
        );

        let schema = r#"root = [0, [0]]"#;
        let cbor_bytes = [0x82, 0x00, 0x81, 0x00];
        let result = cddl::validate_cbor_from_slice(schema, &cbor_bytes, None);
        assert!( //FAILS!
            result.is_ok(),
            "Validation of {:x?} failed: {:?}",
            cbor_bytes,
            result
        );
    }

The first assertion passes, while the second one returns the following error

Validation of [82, 0, 81, 0] failed: Err(Validation([ValidationError { reason: "expected array with length 1, got 2", cddl_location: "", cbor_location: "", is_multi_type_choice: false, is_multi_group_choice: false, is_group_to_choice_enum: false, type_group_name_entry: None }]))
@anweiss anweiss self-assigned this Apr 3, 2024
@anweiss anweiss added the bug Something isn't working label Apr 3, 2024
@anweiss anweiss added this to the v1.0.0 milestone Apr 3, 2024
@anweiss
Copy link
Owner

anweiss commented Apr 3, 2024

Thanks for reporting @gregorydemay. This is going to take a little time for me to fix. The array validation logic I have implemented is a bit of a mess and doesn't properly validate nested arrays.

@ravishankar-hcltech
Copy link

I'm stumbling on this same error. Just checking to see if you have any timelines or pointers for any short term work arounds?

thank you building this wonderful tool & the intuitive error messaging !

@anweiss
Copy link
Owner

anweiss commented Mar 6, 2025

@ravishankar-hcltech working through this as we speak actually! hoping to have a fix up soon! appreciate your patience!

@anweiss
Copy link
Owner

anweiss commented Mar 6, 2025

This should be fixed in #246. Re-open as needed.

@anweiss anweiss closed this as completed Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cbor json validation
Projects
None yet
Development

No branches or pull requests

3 participants