Skip to content

fix: Validate domain length per TLD#3

Merged
imprvhub merged 1 commit intomainfrom
2-two-letter-domains-that-are-not-possible-are-shown-as-available
Jun 18, 2025
Merged

fix: Validate domain length per TLD#3
imprvhub merged 1 commit intomainfrom
2-two-letter-domains-that-are-not-possible-are-shown-as-available

Conversation

@imprvhub
Copy link
Owner

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

  1. Added TLD Minimum Length Data: Introduced a TLD_MIN_LENGTH dictionary to store the minimum allowed length for SLDs under various TLDs. This allows for TLD-specific validation rules.
  2. Implemented Domain Validation Function: Created a new function is_valid_domain_name that performs comprehensive validation of the SLD. This includes checking against the minimum length specified in TLD_MIN_LENGTH, verifying the character set, and applying basic hyphen rules.
  3. Integrated Validation into Checking Logic: The is_valid_domain_name function is now called within check_domain_availability and check_multiple_domains to filter out invalid domains early in the process.
  4. Enhanced Output: Modified the run_domain_checks function to include a list of invalid_domains in 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_LENGTH dictionary 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_checks function has been modified to include the invalid_domains key. 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

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.
@imprvhub imprvhub added enhancement New feature or request validation labels Jun 18, 2025
@imprvhub imprvhub linked an issue Jun 18, 2025 that may be closed by this pull request
@imprvhub imprvhub merged commit 3f1eb92 into main Jun 18, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request validation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Two letter domains that are not possible are shown as available

2 participants