Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Domain-PublicSuffix CPAN distribution.

Report information
The Basics
Id: 77059
Status: resolved
Priority: 0/
Queue: Domain-PublicSuffix

People
Owner: Nobody in particular
Requestors: gavin [...] openfusion.com.au
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.04
Fixed in: (no value)



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
Also, attached is an additional unit test I've been using to test some more problematic edge cases. -G
Subject: Domain-PublicSuffix-0.04-add-problematic-unit-tests.patch
From 85d4f3bb62c526c111917d8ef9077df31e029ff5 Mon Sep 17 00:00:00 2001 From: Gavin Carr <gavin@openfusion.com.au> Date: Sat, 5 May 2012 17:00:33 +1000 Subject: [PATCH] Add 02-problematic.t unit test with problem use cases. --- t/02-problematic.t | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-) create mode 100755 t/02-problematic.t diff --git a/t/02-problematic.t b/t/02-problematic.t new file mode 100755 index 0000000..e27766a --- /dev/null +++ b/t/02-problematic.t @@ -0,0 +1,39 @@ +#!perl + +use Test::More; +use Domain::PublicSuffix; + +my %data = ( + 'www.abc.k12.tx.us' => 'abc.k12.tx.us', + 'www.911.state.tx.us' => 'state.tx.us', + 'www.abington.k12.ma.us' => 'abington.k12.ma.us', + 'www.achd.ada.id.us' => 'ada.id.us', + 'www.alamo_williams_nd.godcool.com' => 'godcool.com', + 'www.poland.gov.pl' => 'poland.gov.pl', + 'www.rjr.dyndns.org' => 'rjr.dyndns.org', + 'www.superior_one.com' => 'superior_one.com', + 'openfusion.com.au' => 'openfusion.com.au', +); + +my @bad = ( + # .au only allows 3lds + 'bogus.au', +); + +ok($dps = new Domain::PublicSuffix, 'constructor ok'); + +for my $hostname (sort keys %data) { + my $root_domain = $dps->get_root_domain($hostname); +# warn "$hostname returned: " . $dps->error . "\n" unless $root_domain; + is($root_domain, $data{$hostname}, "$hostname ok"); +} + +for my $hostname (@bad) { + my $root_domain = $dps->get_root_domain($hostname); + is ($root_domain, undef, "$hostname correctly invalid: " . $dps->error); +} + +done_testing; + +1; + -- 1.7.1
On Tue May 08 06:57:38 2012, GAVINC wrote: Show quoted text
> Also, attached is an additional unit test I've been using to test some > more problematic edge cases. > > -G
I've removed the k12.tx.us, k12.ma.us, and dyndns.org entries, as they don't match up with what's in PublicSuffix, even if they're technically correct. :)
Your patch has been applied in release 0.05. Thank you!