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(integer validation): limit range to the accepted range of the dhis2-core #364

Merged
merged 2 commits into from
Dec 14, 2023

Conversation

Mohammer5
Copy link
Collaborator

@Mohammer5 Mohammer5 commented Dec 12, 2023

Fixes DHIS2-14075

Doc comment from is-integer.js:

 * The `integer` validator of the `@dhis2/ui` library uses
 * `Number.isSafeInterger` to assess whether it the value is a valid integer or
 * not. The range allowed by that methid is -(2^53 - 1) to 2^53 - 1.
 *
 * The `isInteger` validator in the Java core uses the `isValid` method of
 * apache's `IntegerValidator` class (see
 * `dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java`),
 * which allows an integer range from
 * -2147483648 to 2147483647.
 *
 * This validator re-uses `@dhis2/ui`'s validator but restricts the integer to
 * the range allowed by the Java core.
 */```

[DHIS2-14075]: https://dhis2.atlassian.net/browse/DHIS2-14075?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

@Mohammer5 Mohammer5 requested review from tomzemp and a team December 12, 2023 10:15
@dhis2-bot
Copy link
Contributor

dhis2-bot commented Dec 12, 2023

🚀 Deployed on https://pr-364--dhis2-data-entry.netlify.app

@dhis2-bot dhis2-bot temporarily deployed to netlify December 12, 2023 10:17 Inactive
@Mohammer5 Mohammer5 requested review from stian-sandvold and removed request for a team December 12, 2023 10:17
Copy link
Member

@tomzemp tomzemp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach looks good. I'm not sure the check is working totally as intended (see comments).

Two other things I noticed (not related to your changes):

  • I tried testing with an existing data element of type INTEGER (BCG Doses Given, which is on Child Health data set) (https://debug.dhis2.org/dev/api/dataElements/s46m5MS0hxu), and there it seemed like any negative values were being rejected by the backend 🤔
  • it seems all validations are rerunning any time any value in the form changes. I guess the validation checks aren't very intensive, but that seems like we wouldn't want that?

src/shared/validation/is-integer.js Outdated Show resolved Hide resolved
src/shared/validation/is-integer.js Outdated Show resolved Hide resolved
@Birkbjo
Copy link
Member

Birkbjo commented Dec 13, 2023

Note that this touches code that was changed in: #357

@Mohammer5
Copy link
Collaborator Author

@Birkbjo interesting! I assume min-max limits are also constrained by the BE's integer validation, but that's just an uneducated guess. Do you know @stian-sandvold?

@stian-sandvold
Copy link

@Birkbjo interesting! I assume min-max limits are also constrained by the BE's integer validation, but that's just an uneducated guess. Do you know @stian-sandvold?

I don't think we validate those numbers anywhere, but we do store them as ints.

@Mohammer5 Mohammer5 requested a review from tomzemp December 14, 2023 09:23
@dhis2-bot dhis2-bot temporarily deployed to netlify December 14, 2023 09:28 Inactive
Copy link
Member

@tomzemp tomzemp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

@Mohammer5
Copy link
Collaborator Author

@Birkbjo: confirmed by @stian-sandvold: We can assume that min-max limits also adhere to the integer range restrictions

@Mohammer5 Mohammer5 merged commit 0d3d41c into master Dec 14, 2023
12 checks passed
dhis2-bot added a commit that referenced this pull request Dec 14, 2023
## [100.3.9](v100.3.8...v100.3.9) (2023-12-14)

### Bug Fixes

* **integer validation:** limit range to the accepted range of the dhis2-core ([#364](#364)) ([0d3d41c](0d3d41c))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 100.3.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

5 participants