fix(isFQDN): skip numeric-label check when require_tld is false#2726
Open
xxiaoxiong wants to merge 1 commit into
Open
fix(isFQDN): skip numeric-label check when require_tld is false#2726xxiaoxiong wants to merge 1 commit into
xxiaoxiong wants to merge 1 commit into
Conversation
When require_tld is false, single-label names like '192' or '10' should be valid since there is no TLD to evaluate. The existing check at line 47 (outside the require_tld block) was unconditionally rejecting any string whose last dot-segment is all digits, even when no TLD is required at all. The same constraint is already enforced inside the require_tld block (line 36 rejects non-alphabetic TLDs), so wrapping the redundant check in the same require_tld condition has no effect when require_tld is true and correctly allows numeric single-labels when require_tld is false. Fixes validatorjs#2425
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.
Problem
When
require_tld: false, single-label names that are all-numeric (e.g.192,10) are incorrectly rejected byisFQDN.Root cause: The check at line 47 (outside the
require_tldblock) was unconditionally rejecting any label whose last dot-segment consists solely of digits:When
require_tld: truethis is fine — TLDs like.123are always disallowed. But whenrequire_tld: falsethere is no TLD at all; the last segment is just the only label, and a purely numeric label should be permitted.The same constraint is already enforced inside the
require_tldblock (line 36 rejects non-alphabetic TLDs), so the outer check is redundant for therequire_tld: truecase and harmful for therequire_tld: falsecase.Fix
Guard the check with
options.require_tld:Tests
Added test cases for
{ require_tld: false }intest/validators/isFQDN.test.jscovering:google.com) still passlocalhost) pass192,10) now correctly passFixes #2425