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

Fix atjson-mode round-trip edge-cases #10

Open
DavidBuchanan314 opened this issue Nov 25, 2024 · 2 comments
Open

Fix atjson-mode round-trip edge-cases #10

DavidBuchanan314 opened this issue Nov 25, 2024 · 2 comments

Comments

@DavidBuchanan314
Copy link
Owner

DavidBuchanan314 commented Nov 25, 2024

Current behaviours:

>>> cbrrr.encode_dag_cbor({"$bytes": "aa", "abc": "def"}, atjson_mode=True)
b'\xa2cabccdeff$bytesbaa' # should raise exception, not valid under atproto data model
>>> cbrrr.decode_dag_cbor(cbrrr.encode_dag_cbor({"$bytes": False}), atjson_mode=True)
{'$bytes': False} # should raise exception during decode, not valid under atproto data model

(same for $link)

@DavidBuchanan314
Copy link
Owner Author

DavidBuchanan314 commented Nov 25, 2024

I like having the ability to work with "weird" objects, for testing/edge-case-poking purposes. I might introduce a new mode, atjson_mode="strict", which forbids these things. It can also forbid floats.

Or maybe atjson_mode="sloppy" can retain the looser behaviour, with atjson_mode=True being maximally strict.

@DavidBuchanan314
Copy link
Owner Author

Concretely, strict decode should:

  • Reject $link, $bytes as object keys
  • Reject floats

Strict encode should:

  • Reject objects with $link or $bytes keys that also have other keys
  • Reject floats

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant