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

feat(parseutil) Add Safe variants of ParseInt* #37

Merged
merged 1 commit into from
Apr 27, 2022

Conversation

cipherboy
Copy link
Contributor

@cipherboy cipherboy commented Mar 21, 2022

These proposed variants allow parsing smaller data types (such as ints)
from larger data types (the int64 returned by ParseInt{,Slice}(...)),
validating that they are within the requested range prior to casting.
With the SafeParseIntRange(...) helper, we also allow validation of the
maximum expected number of elements in the slice.

Signed-off-by: Alexander Scheel <[email protected]>

--

https://hashicorp.atlassian.net/browse/VAULT-3892 has some context around this change for those with access.

@cipherboy cipherboy added the enhancement New feature or request label Mar 21, 2022
@cipherboy cipherboy requested a review from sgmiller March 21, 2022 18:23
sgmiller
sgmiller previously approved these changes Mar 21, 2022
@cipherboy
Copy link
Contributor Author

Added tests for the feature.

sgmiller
sgmiller previously approved these changes Mar 22, 2022
@sgmiller sgmiller requested a review from briankassouf March 22, 2022 17:57
jefferai
jefferai previously approved these changes Apr 25, 2022
Copy link
Member

@jefferai jefferai left a comment

Choose a reason for hiding this comment

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

LGTM but please add method comments

@cipherboy cipherboy dismissed stale reviews from jefferai and sgmiller via 84920c7 April 25, 2022 20:23
@cipherboy
Copy link
Contributor Author

Thanks for the feedback, updated. :-)

briankassouf
briankassouf previously approved these changes Apr 26, 2022
Copy link

@briankassouf briankassouf left a comment

Choose a reason for hiding this comment

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

Thanks for adding all the doc comments

These proposed variants allow parsing smaller data types (such as ints)
from larger data types (the int64 returned by ParseInt{,Slice}(...)),
validating that they are within the requested range prior to casting.
With the SafeParseIntRange(...) helper, we also allow validation of the
maximum expected number of elements in the slice.

Added missing method doc strings to all methods.

Signed-off-by: Alexander Scheel <[email protected]>
@sgmiller sgmiller self-requested a review April 27, 2022 16:20
@sgmiller sgmiller merged commit db74f13 into hashicorp:main Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants