-
Notifications
You must be signed in to change notification settings - Fork 97
fix(ibm-integer-attributes): add validation for type integer ranges #756
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fef2e39
fix(integer-attributes): add validation for type integer ranges
diatrcz 41289b0
fix(integer-attributes): fix values in test cases
diatrcz 634cc20
fix(ibm-integer-attributes): fix values in test cases
diatrcz d823fbb
fix(ibm-integer-attributes): add format check for integer schemas
diatrcz 3d28ed4
fix(ibm-integer-attributes): fix values in test cases
diatrcz bfed67d
Update packages/ruleset/src/functions/integer-attributes.js
diatrcz 2e7e6ab
fix(ibm-integer-attributes): fix logic in integer value check
diatrcz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,13 @@ module.exports = function (schema, _opts, context) { | |
| // These are the valid format values that can be used with integer schemas. | ||
| const intFormats = ['int32', 'int64']; | ||
|
|
||
| //These are the minimum and maximum values for integer schemas | ||
| const int32Minimum = -2147483648; | ||
| const int32Maximum = 2147483647; | ||
|
|
||
| const int64Minimum = -9007199254740991; | ||
| const int64Maximum = 9007199254740991; | ||
|
|
||
| /** | ||
| * This function performs various checks on an integer schema property to make sure it | ||
| * contains the "minimum", "maximum" attributes. | ||
|
|
@@ -50,10 +57,13 @@ function integerBoundaryErrors(schema, path) { | |
|
|
||
| const errors = []; | ||
|
|
||
| if (isDefined(format) && !intFormats.includes(format)) { | ||
| if ( | ||
| !isDefined(format) || | ||
| (isDefined(format) && !intFormats.includes(format)) | ||
| ) { | ||
| errors.push({ | ||
| message: `Integer schemas should specify format as one of ${intFormats.join( | ||
| '.' | ||
| ', ' | ||
| )}`, | ||
| path, | ||
| }); | ||
|
|
@@ -70,11 +80,40 @@ function integerBoundaryErrors(schema, path) { | |
| path, | ||
| }); | ||
| } | ||
| if (isDefined(minimum) && isDefined(maximum) && minimum > maximum) { | ||
| errors.push({ | ||
| message: `'minimum' cannot be greater than 'maximum'`, | ||
| path, | ||
| }); | ||
| if (isDefined(minimum) && isDefined(maximum)) { | ||
| if (minimum > maximum) { | ||
| errors.push({ | ||
| message: `'minimum' cannot be greater than 'maximum'`, | ||
| path, | ||
| }); | ||
| } | ||
| if (format === 'int32') { | ||
| if (minimum > int32Maximum || minimum < int32Minimum) { | ||
| errors.push({ | ||
| message: `'minimum' value is out of safe range`, | ||
| path, | ||
| }); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might not want to gate this on |
||
| if (maximum > int32Maximum || maximum < int32Minimum) { | ||
| errors.push({ | ||
| message: `'maximum' value is out of safe range`, | ||
| path, | ||
| }); | ||
| } | ||
| } else { | ||
| if (minimum > int64Maximum || minimum < int64Minimum) { | ||
| errors.push({ | ||
| message: `'minimum' value is out of safe range`, | ||
| path, | ||
| }); | ||
| } | ||
| if (maximum > int64Maximum || maximum < int64Minimum) { | ||
| errors.push({ | ||
| message: `'maximum' value is out of safe range`, | ||
| path, | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return errors; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.