Subject: | Feature request: optionally allow underscores in hostnames |
Hi Nick,
As discussed, I'd like to be able to switch on the
domain_allow_underscore flag to Domain::ValidateDomain, for cases in
which we'd like to allow RFC-noncompliant underscores to occur in
hostnames. I've added this as an additional flag to the constructor in
the attached patch. Please review.
Cheers,
Gavin
Subject: | Domain-PublicSuffix-0.04-allow-domain-underscores.patch |
From 355b0f7d48ac123389bc91367c71e1245fbeca33 Mon Sep 17 00:00:00 2001
From: Gavin Carr <gavin@openfusion.com.au>
Date: Tue, 8 May 2012 18:00:32 +1000
Subject: [PATCH] Add domain_allow_underscore flag to constructor.
---
lib/Domain/PublicSuffix.pm | 22 ++++++++++++++++++----
1 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/lib/Domain/PublicSuffix.pm b/lib/Domain/PublicSuffix.pm
index 65bd346..87fef4d 100755
--- a/lib/Domain/PublicSuffix.pm
+++ b/lib/Domain/PublicSuffix.pm
@@ -11,6 +11,7 @@ our $VERSION = '0.04';
__PACKAGE__->mk_accessors(qw/
data_file
+ domain_allow_underscore
tld_tree
error
root_domain
@@ -81,14 +82,26 @@ Returns the true DNS tld of the last parsed domain. For the domain
=over 4
-=item new ({ optional data_file })
+=item new ({ optional arguments })
Instantiate a PublicSuffix object. It is best to instantiate an object
and continue calling get_root_domain instead of continually recreating the
object, as the data file is read and parsed on instantiation.
-Can take a data_file argument inside of a hashref, as a fully qualified path,
-to override the effective_tld_names.dat file.
+Can take a hashref of arguments:
+
+=over 4
+
+=item data_file
+
+A fully qualified path, to override the effective_tld_names.dat file.
+
+=item domain_allow_underscore
+
+A flag to indicate that underscores should be allowed in hostnames
+(contra to the RFCs). Default: undef.
+
+=back
=back
@@ -281,7 +294,8 @@ sub _validate_domain {
my $is_valid = Data::Validate::Domain::is_domain(
$domain,
{
- 'domain_private_tld' => qr/^[a-z0-9]+$/
+ 'domain_allow_underscore' => $self->domain_allow_underscore,
+ 'domain_private_tld' => qr/^[a-z0-9]+$/,
}
);
return 1 if ($is_valid);
--
1.7.1