Skip to content

Commit

Permalink
Define terms more clearly
Browse files Browse the repository at this point in the history
  • Loading branch information
tinohager committed Feb 13, 2024
1 parent c5ac874 commit 57cb89e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
18 changes: 9 additions & 9 deletions src/Nager.PublicSuffix/DomainInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public class DomainInfo
public string? RegistrableDomain { get; private set; }

/// <summary>
/// Fully qualified hostname (FQDN)
/// Fully qualified domain name (FQDN)
/// </summary>
public string? Hostname { get; private set; }
public string? FullyQualifiedDomainName { get; private set; }

/// <summary>
/// The matching public suffix Rule
/// The matching Rule of the PublicSuffixList
/// </summary>
public TldRule? TopLevelDomainRule { get; private set; }

Expand All @@ -63,13 +63,13 @@ public DomainInfo(
/// <summary>
/// Domain Info
/// </summary>
/// <param name="domain"></param>
/// <param name="fullyQualifiedDomainName"></param>
/// <param name="tldRule"></param>
public DomainInfo(
string domain,
string fullyQualifiedDomainName,
TldRule tldRule)
{
if (string.IsNullOrEmpty(domain))
if (string.IsNullOrEmpty(fullyQualifiedDomainName))
{
return;
}
Expand All @@ -79,19 +79,19 @@ public DomainInfo(
return;
}

var domainParts = domain.Split('.').Reverse();
var domainParts = fullyQualifiedDomainName.Split('.').Reverse();
var ruleParts = tldRule.Name.Split('.').Skip(tldRule.Type == TldRuleType.WildcardException ? 1 : 0).Count();

var topLevelDomain = string.Join(".", domainParts.Take(ruleParts).Reverse());
var registrableDomain = string.Join(".", domainParts.Take(ruleParts + 1).Reverse());

if (domain.Equals(topLevelDomain))
if (fullyQualifiedDomainName.Equals(topLevelDomain))
{
return;
}

this.TopLevelDomainRule = tldRule;
this.Hostname = domain;
this.FullyQualifiedDomainName = fullyQualifiedDomainName;
this.TopLevelDomain = topLevelDomain;
this.RegistrableDomain = registrableDomain;

Expand Down
24 changes: 12 additions & 12 deletions src/Nager.PublicSuffix/DomainParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public DomainParser(
}

/// <inheritdoc/>
public DomainInfo? Parse(Uri domain)
public DomainInfo? Parse(Uri fullyQualifiedDomainName)
{
var partlyNormalizedDomain = domain.Host;
var normalizedHost = domain.GetComponents(UriComponents.NormalizedHost, UriFormat.UriEscaped); //Normalize punycode
var partlyNormalizedDomain = fullyQualifiedDomainName.Host;
var normalizedHost = fullyQualifiedDomainName.GetComponents(UriComponents.NormalizedHost, UriFormat.UriEscaped); //Normalize punycode

var parts = normalizedHost
.Split('.')
Expand All @@ -44,9 +44,9 @@ public DomainParser(
}

/// <inheritdoc/>
public DomainInfo? Parse(string domain)
public DomainInfo? Parse(string fullyQualifiedDomainName)
{
var parts = this._domainNormalizer.PartlyNormalizeDomainAndExtractFullyNormalizedParts(domain, out string? partlyNormalizedDomain);
var parts = this._domainNormalizer.PartlyNormalizeDomainAndExtractFullyNormalizedParts(fullyQualifiedDomainName, out string? partlyNormalizedDomain);
if (parts == null)
{
return null;
Expand All @@ -56,36 +56,36 @@ public DomainParser(
}

/// <inheritdoc/>
public bool IsValidDomain(string domain)
public bool IsValidDomain(string fullyQualifiedDomainName)
{
if (string.IsNullOrEmpty(domain))
if (string.IsNullOrEmpty(fullyQualifiedDomainName))
{
return false;
}

if (Uri.TryCreate(domain, UriKind.Absolute, out _))
if (Uri.TryCreate(fullyQualifiedDomainName, UriKind.Absolute, out _))
{
return false;
}

if (!Uri.TryCreate($"http://{domain}", UriKind.Absolute, out var uri))
if (!Uri.TryCreate($"http://{fullyQualifiedDomainName}", UriKind.Absolute, out var uri))
{
return false;
}

if (!uri.DnsSafeHost.Equals(domain, StringComparison.OrdinalIgnoreCase))
if (!uri.DnsSafeHost.Equals(fullyQualifiedDomainName, StringComparison.OrdinalIgnoreCase))
{
return false;
}

if (domain[0] == '*')
if (fullyQualifiedDomainName[0] == '*')
{
return false;
}

try
{
var parts = this._domainNormalizer.PartlyNormalizeDomainAndExtractFullyNormalizedParts(domain, out string? partlyNormalizedDomain);
var parts = this._domainNormalizer.PartlyNormalizeDomainAndExtractFullyNormalizedParts(fullyQualifiedDomainName, out string? partlyNormalizedDomain);
if (parts == null)
{
return false;
Expand Down
20 changes: 10 additions & 10 deletions src/Nager.PublicSuffix/IDomainParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ namespace Nager.PublicSuffix
public interface IDomainParser
{
/// <summary>
/// Parse the DomainInfo from <paramref name="domain"/>.
/// Parse the DomainInfo from <paramref name="fullyQualifiedDomainName"/>.
/// </summary>
/// <param name="domain">The domain to parse.</param>
/// <param name="fullyQualifiedDomainName">The fully qualified domain name (FQDN) to parse</param>
/// <returns>DomainInfo object</returns>
DomainInfo? Parse(string domain);
DomainInfo? Parse(string fullyQualifiedDomainName);

/// <summary>
/// Parse the DomainInfo from <paramref name="domain"/>.
/// Parse the DomainInfo from <paramref name="fullyQualifiedDomainName"/>.
/// </summary>
/// <param name="domain">The domain to parse.</param>
/// <param name="fullyQualifiedDomainName">The fully qualified domain name (FQDN) to parse</param>
/// <returns>DomainInfo object</returns>
DomainInfo? Parse(Uri domain);
DomainInfo? Parse(Uri fullyQualifiedDomainName);

/// <summary>
/// Checks if the <paramref name="domain"/> is valid.
/// Checks if the <paramref name="fullyQualifiedDomainName"/> is valid.
/// </summary>
/// <param name="domain">The domain to check.</param>
/// <returns>Returns <strong>true</strong> if the <paramref name="domain"/> is valid.</returns>
bool IsValidDomain(string domain);
/// <param name="fullyQualifiedDomainName">The fully qualified domain name (FQDN) to check</param>
/// <returns>Returns <strong>true</strong> if the <paramref name="fullyQualifiedDomainName"/> is valid.</returns>
bool IsValidDomain(string fullyQualifiedDomainName);
}
}

0 comments on commit 57cb89e

Please sign in to comment.