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

Prevent invalid JSON payload generation with Infinity #917

Open
guillett opened this issue Nov 26, 2019 · 3 comments · Fixed by #1223
Open

Prevent invalid JSON payload generation with Infinity #917

guillett opened this issue Nov 26, 2019 · 3 comments · Fixed by #1223
Assignees
Labels
kind:fix Bugs are defects and failure demand.

Comments

@guillett
Copy link
Member

Hi there!

I really enjoy OpenFisca, but I recently encountered an issue.

Here is what I did:

I run https://mes-aides.gouv.fr/ and receive user emails.

I tried to debug with self made tool (https://betagouv.github.io/openfisca-tracer) but the JSON payload could not be parsed.

I figured it was because of the Infinity presence in the payload.

Here is what I expected to happen:

Infinity should not be present as it is not a valid JSON token cf. StackOverflow.

Finite numbers are stringified as if by calling ToString(number). NaN and Infinity regardless of sign are represented as the String null.

Here is data (or links to it) that can help you reproduce this issue:

{
    "individus": {
        "_": {}
    },
    "familles": {
        "_": {
            "parents": [
                "_"
            ]
        }
    },
    "menages": {
        "_": {
            "niveau_de_vie": {
                "2019": null
            },
            "revenu_disponible": {
                "2019": 120
            },
            "unites_consommation": {
                "2019": 0
            },
            "personne_de_reference": [
                "_"
            ]
        }
    }
}

Context

I identify more as a:

  • Developer (I create tools that use the existing OpenFisca code).
@bonjourmauko bonjourmauko added the kind:fix Bugs are defects and failure demand. label Dec 10, 2019
@bonjourmauko
Copy link
Member

Hi @guillett, thanks for reporting this!

I tried with the payload you provided, without being able to reproduce the issue. Do you have any additional elements I could use to reproduce it?

screencapture-betagouv-github-io-openfisca-tracer-2019-12-10-16_23_01

@guillett
Copy link
Member Author

guillett commented Dec 12, 2019

I hacked https://betagouv.github.io/openfisca-tracer/ to replace Infinity with -1 😁

You can your browser dev tools to look at the returned payload from the POST /trace request.

@bonjourmauko
Copy link
Member

Hi @guillett, this should have been fixed in #1223. There is a specific case for infinity now handled as a -1:

    @classmethod
    def eternity(cls) -> t.Instant:
        """Return an eternity instant."""
        return cls((-1, -1, -1))

Can you confirm? cc @benjello

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:fix Bugs are defects and failure demand.
Projects
Status: Discussing / Discovering
Development

Successfully merging a pull request may close this issue.

2 participants