Merged
Conversation
Closes #2 This commit addresses issue #2 by introducing robust domain name validation, specifically preventing the listing of second-level domains (SLDs) that do not meet the minimum length requirements or other syntax rules for their respective Top-Level Domains (TLDs). Key changes include: - Added `TLD_MIN_LENGTH` dictionary to store minimum allowed lengths for SLDs under various TLDs. - Implemented `is_valid_domain_name` function to perform comprehensive validation of the SLD (min length, character set, hyphen rules) before performing network checks. - Integrated `is_valid_domain_name` into `check_domain_availability` and `check_multiple_domains` to filter out invalid domains early. - Enhanced `run_domain_checks` to include `invalid_domains` in the output, providing clear feedback to the user about why an SLD might not be valid for certain TLDs (e.g., "Minimum length: 3 chars"). This ensures that only genuinely valid and available domains are reported, resolving the reported issue where two-letter SLDs (e.g., `ab` in `ab.ch`, `ab.at`) were incorrectly shown as available.
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.
Prevent invalid two-letter domains from being listed as available
Summary
This pull request addresses issue #2 by implementing robust domain name validation. It prevents second-level domains (SLDs) that do not meet minimum length requirements or other syntax rules for their respective Top-Level Domains (TLDs) from being processed and incorrectly reported as available.
Motivation
Previously, the application would perform DNS/WHOIS checks on domains even if their structure was invalid according to TLD-specific rules, such as minimum length. This led to scenarios where invalid two-letter domains (e.g.,
ab.ch,ab.at) were incorrectly shown as available because they passed basic syntax but failed TLD-specific constraints. This PR resolves this by validating domains before network checks, ensuring only genuinely valid domains are processed and reported.Closes #2
Changes Made
TLD_MIN_LENGTHdictionary to store the minimum allowed length for SLDs under various TLDs. This allows for TLD-specific validation rules.is_valid_domain_namethat performs comprehensive validation of the SLD. This includes checking against the minimum length specified inTLD_MIN_LENGTH, verifying the character set, and applying basic hyphen rules.is_valid_domain_namefunction is now called withincheck_domain_availabilityandcheck_multiple_domainsto filter out invalid domains early in the process.run_domain_checksfunction to include a list ofinvalid_domainsin its output. This list provides clear feedback to the user about which domains were deemed invalid and, where applicable, the reason (e.g., "Minimum length: 3 chars").Technical Implementation
The core change involves adding a validation step early in the domain checking pipeline. By checking validity based on TLD rules before initiating network requests, we avoid unnecessary DNS/WHOIS lookups for domains that are inherently invalid.
Regarding the minimum length validation specifically, comprehensive, readily available data on the precise minimum SLD length requirements for all 50+ TLDs is difficult to find. To ensure robust validation and prevent potential registration issues, the current implementation conservatively sets the minimum SLD length to 3 characters for all TLDs without exception. While some TLDs may permit 2-character SLDs, this blanket rule prioritizes preventing invalid registrations based on common requirements. The
TLD_MIN_LENGTHdictionary is included to provide a configurable way to handle varying TLD requirements if more specific data becomes available in the future. Future research and data acquisition may allow for more granular, TLD-specific minimum length rules to be implemented.Important Notes
The output structure of the
run_domain_checksfunction has been modified to include theinvalid_domainskey. Any code consuming the output of this function should be updated to handle this new key if necessary.Impact
This enhancement significantly improves the accuracy and reliability of the domain availability checks. Users will no longer receive misleading "available" results for domains that are syntactically impossible to register. The explicit listing of invalid domains with reasons also provides better feedback, helping users understand why certain domain requests were not processed.
Closes #2