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

There are no tests to ensure that floats fail #22

Open
Half-Shot opened this issue Mar 1, 2019 · 8 comments
Open

There are no tests to ensure that floats fail #22

Half-Shot opened this issue Mar 1, 2019 · 8 comments

Comments

@Half-Shot
Copy link

Half-Shot commented Mar 1, 2019

As per spec:

Numbers in the JSON must be integers in the range [-(2**53)+1, (2**53)-1].

There isn't any code that checks for floats, either.

@richvdh
Copy link
Member

richvdh commented Jun 5, 2019

looks like #17 fixes this

@clokep
Copy link
Member

clokep commented Jul 23, 2020

Seems like this would be nice, but I don't think we can do it -- see matrix-org/synapse#7381 and related issues.

@richvdh
Copy link
Member

richvdh commented Jul 23, 2020

I think we should make it turn-on-and-off-able: add an option to reject floats.

@ShadowJonathan
Copy link

This is still an issue, I was looking for a method by which synapse ensures that ints do not exceed their maximum value, and i found none.

#17 is closed, I'll look into making a new PR.

@DMRobertson
Copy link
Contributor

Note that the spec says:

Float values are not permitted by this encoding.

and the grammar for only permits integer literals in number.

@DMRobertson
Copy link
Contributor

Additionally: it's not just that the tests fail, but we don't reject floats whatsoever:

>>> canonicaljson.encode_canonical_json({"x": 1.23})
b'{"x":1.23}'

@DMRobertson DMRobertson added the bug label Jun 6, 2022
@DMRobertson
Copy link
Contributor

We could add some kind of opt-in strict mode to this function (for use in v6 rooms and up). But whatever we do, we'd need to be careful to maintain backwards compatibility because existing Synapse releases will install canonicaljson willy-nilly without any upper bound.

@richvdh
Copy link
Member

richvdh commented Jun 7, 2022

But whatever we do, we'd need to be careful to maintain backwards compatibility because existing Synapse releases will install canonicaljson willy-nilly without any upper bound.

I wonder if we should just plan to break such old Synapse releases. We could deprecate the encode_canonical_json name in favour of some other name, and (eventually) drop encode_canonical_json altogether (with a major semver bump). That would leave old Synapses obviously rather than subtly broken, and will leave python-canonicaljson without the footgun of a function called encode_canonical_json which doesn't encode canonical json.

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

No branches or pull requests

5 participants