Correct IP validation logic order-of-operations#92
Open
YSaxon wants to merge 1 commit intopbojinov:masterfrom
Open
Correct IP validation logic order-of-operations#92YSaxon wants to merge 1 commit intopbojinov:masterfrom
YSaxon wants to merge 1 commit intopbojinov:masterfrom
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request fixes the logic used for validating IP addresses.
Old code:
In pseudocode
The existing code evaluates regexes.ipv6.test(value) regardless of whether existy(value) returns true or false. This happens due to the parenthesis placement, which only associates existy(value) with regexes.ipv4.test(value).
New code:
In psuedocode:
The updated logic ensures that both regexes.ipv4.test(value) and regexes.ipv6.test(value) are evaluated only if existy(value) is true. This is achieved by encompassing the OR condition within parentheses, applying the existy(value) check to both IPv4 and IPv6 conditions.
Presumably the ipv6 regex doesn't throw an error when handling a null value, or you would have had bug reports about this before. So you could also consider just removing the null check. But if you want to keep the null check in there for efficiency, to quickly return false without applying the ipv4 regex if there is nothing to check, then this pull request will double that efficiency gain by also avoiding applying the ipv6 regex check to null values, without any additional null checking.