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

tstr type allows maps? #82

Closed
adzialocha opened this issue Jan 16, 2021 · 6 comments · Fixed by #85 or #79
Closed

tstr type allows maps? #82

adzialocha opened this issue Jan 16, 2021 · 6 comments · Fixed by #85 or #79
Assignees
Labels
bug Something isn't working json validation
Milestone

Comments

@adzialocha
Copy link

Thank you for this fantastic implementation of CDDL! ✨

I've stumbled upon the following issue and wonder if it might be a bug?
The following CDDL schema (wrongly?) allows maps as values in the fields map even though only tstr types are permitted:

message = {
    fields: {
        + tstr => tstr
    }
}

This CBOR here (with diagnostic JSON) gets accepted by this schema while I would expect an error:

A1666669656C6473A16474657374A164546578746F48656C6C6F2C204D65737361676521
{
  "fields": {
    "test": {
      "Text": "Hello, Message"
    }
  }
}
@anweiss
Copy link
Owner

anweiss commented Jan 25, 2021

Good catch, thanks for reporting @adzialocha! Fixing in #85.

@anweiss anweiss self-assigned this Jan 25, 2021
@anweiss anweiss added bug Something isn't working validation json labels Jan 25, 2021
@adzialocha
Copy link
Author

Thank you for this fast fix!

@anweiss
Copy link
Owner

anweiss commented Jan 25, 2021

This has been fixed as of v0.8.6. Pleas reopen if you are still experiencing issues.

@adzialocha
Copy link
Author

This might still be a problem @anweiss as maps are still considered valid strings in this test using version v0.8.6.. Maybe we're doing something wrong with the schema, but just to be sure I'm posting this here as well:

let schema = r#"
    message = {
        fields: {
            + tstr => tstr,
        }
    }
"#;

// {"fields": {"test":  "Hello, Message!"}}
let correct_cbor = "A1666669656C6473A164746573746F48656C6C6F2C204D65737361676521";

// {"fields": {"test": {"Text": "Hello, Message!"}}}
let invalid_cbor = "A1666669656C6473A16474657374A164546578746F48656C6C6F2C204D65737361676521";

assert!(cddl::validate_cbor_from_slice(schema, correct_cbor.as_bytes()).is_ok());
assert!(cddl::validate_cbor_from_slice(schema, invalid_cbor.as_bytes()).is_err());

@anweiss
Copy link
Owner

anweiss commented Feb 13, 2021

Hmmm ... I think you're right. Reopening to do some more troubleshooting here. Thanks for reporting.

@anweiss anweiss reopened this Feb 13, 2021
@anweiss anweiss added this to the v1.0.0 milestone Aug 30, 2021
anweiss added a commit that referenced this issue Sep 13, 2021
@anweiss
Copy link
Owner

anweiss commented Sep 13, 2021

Hey @adzialocha this is (finally) being fixed in #79

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working json validation
Projects
None yet
2 participants