Subject: | Bug with domain segments that evaluate to false |
Hi Nick,
Just noticed there's a bug with domain segments that evaluate to false
e.g. www.1.com correctly returns 1.com as root domain, but www.0.com
just returns 'com'.
Failing unit test patch and fix attached.
Cheers,
Gavin
Subject: | Domain-PublicSuffix-0.08-bugfix-false-segments.patch |
From 4a626b5bf4970032706d455f4bfd0497bd8fc544 Mon Sep 17 00:00:00 2001
From: Gavin Carr <gavin@openfusion.com.au>
Date: Mon, 18 Mar 2013 12:36:28 +1100
Subject: [PATCH] Add fix for domain segments evaluating to false.
---
lib/Domain/PublicSuffix.pm | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/Domain/PublicSuffix.pm b/lib/Domain/PublicSuffix.pm
index bf8e507..49a8aaf 100755
--- a/lib/Domain/PublicSuffix.pm
+++ b/lib/Domain/PublicSuffix.pm
@@ -165,7 +165,7 @@ sub get_root_domain {
while ( !$self->suffix and scalar(@domain_array) > 0 ) {
my $sub = pop(@domain_array);
- next if (!$sub);
+ next if (! defined $sub);
# check if $sub.$last is a root
if ( defined $last->{$sub} and scalar(keys %{$last->{$sub}}) == 0 ) {
--
1.7.1
Subject: | Domain-PublicSuffix-0.08-0.com.unit-test.patch |
From 67e204bed82569a5f636a6a452cfff551a607480 Mon Sep 17 00:00:00 2001
From: Gavin Carr <gavin@openfusion.com.au>
Date: Mon, 18 Mar 2013 12:35:10 +1100
Subject: [PATCH] Add failing test for www.0.com to 01-core.t.
---
t/01-core.t | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/t/01-core.t b/t/01-core.t
index bd97aca..960fdb4 100755
--- a/t/01-core.t
+++ b/t/01-core.t
@@ -15,6 +15,9 @@ is( $ps->get_root_domain('www.google.co.uk'), 'google.co.uk', 'www-to-root-co-uk
is( $ps->tld(), 'uk', , 'root-to-root-co-uk-tld' );
is( $ps->suffix(), 'co.uk', , 'root-to-root-co-uk-etld' );
+is( $ps->get_root_domain('www.0.com'), '0.com' , '0.com' );
+is( $ps->tld(), 'com', , '0.com-tld' );
+
is( $ps->get_root_domain('not_valid_at_all'), undef , 'invalid-domain' );
is( $ps->error, 'Malformed domain', , 'domain-error' );
--
1.7.1