From 912bc6291ab804ba1c42c223922745e0bd952b5b Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 18 Aug 2024 01:14:51 -0400 Subject: [PATCH] group_hosts_by: Treat `undef` as unset for consistency with `opt` The `opt` function falls back to global/default if the value is undefined, even if it is explicitly set to `undef`. `group_hosts_by` should behave the same. --- ddclient.in | 2 +- t/group_hosts_by.pl | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ddclient.in b/ddclient.in index 7d244db..d8fbbf8 100755 --- a/ddclient.in +++ b/ddclient.in @@ -3381,7 +3381,7 @@ sub group_hosts_by { my %groups; my %cfgs; for my $h (@$hosts) { - my %cfg = map({ ($_ => $config{$h}{$_}); } grep(exists($config{$h}{$_}), @attrs)); + my %cfg = map({ ($_ => $config{$h}{$_}); } grep(defined($config{$h}{$_}), @attrs)); my $sig = repr(\%cfg, Indent => 0); push(@{$groups{$sig}}, $h); $cfgs{$sig} = \%cfg; diff --git a/t/group_hosts_by.pl b/t/group_hosts_by.pl index 4e2c29f..4cf25a1 100644 --- a/t/group_hosts_by.pl +++ b/t/group_hosts_by.pl @@ -72,7 +72,9 @@ my @test_cases = ( want => [ {cfg => {falsy => 0}, hosts => [$h1]}, {cfg => {falsy => ''}, hosts => [$h2]}, - {cfg => {falsy => undef}, hosts => [$h3]}, + # undef intentionally becomes unset because undef always means "fall back to global or + # default". + {cfg => {}, hosts => [$h3]}, ], }, { @@ -80,8 +82,9 @@ my @test_cases = ( groupby => [qw(maybeunset)], want => [ {cfg => {maybeunset => 'unique'}, hosts => [$h1]}, - {cfg => {maybeunset => undef}, hosts => [$h2]}, - {cfg => {}, hosts => [$h3]}, + # undef intentionally becomes unset because undef always means "fall back to global or + # default". + {cfg => {}, hosts => [$h2, $h3]}, ], }, {