From 4bbdd551b4b98db8a79ba70c7beb67f24c2f6812 Mon Sep 17 00:00:00 2001 From: Henry Baragar Date: Fri, 2 Jan 2009 20:41:00 +0000 Subject: [PATCH] Ignore leading/trailing whitespace in config files git-svn-id: https://svn.perl.org/qpsmtpd/trunk@966 958fd67b-6ff1-0310-b445-bb7760255be9 --- Changes | 2 ++ config.sample/relayclients | 5 +++-- lib/Qpsmtpd.pm | 4 +++- t/config.t | 5 +++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index fe94e58..1cff761 100644 --- a/Changes +++ b/Changes @@ -62,6 +62,8 @@ New config option "spool_perms" to set permissions of spool_dir (Jared Johnson) + leading/trailing whitespace in config files is ignored (Henry Baragar) + 0.43 - February 5, 2008 (This release was mostly done by Matt Sergeant and Hanno Hecker) diff --git a/config.sample/relayclients b/config.sample/relayclients index d0990b2..5bbb91d 100644 --- a/config.sample/relayclients +++ b/config.sample/relayclients @@ -1,4 +1,5 @@ # Format is IP, or IP part with trailing dot # e.g. "127.0.0.1", or "192.168." -127.0.0.1 -192.168. +127.0.0.1 +# leading/trailing whitespace is ignored + 192.168. diff --git a/lib/Qpsmtpd.pm b/lib/Qpsmtpd.pm index 1238ae0..2e54353 100644 --- a/lib/Qpsmtpd.pm +++ b/lib/Qpsmtpd.pm @@ -239,7 +239,9 @@ sub _config_from_file { open CF, "<$configfile" or warn "$$ could not open configfile $configfile: $!" and return; my @config = ; chomp @config; - @config = grep { length($_) and $_ !~ m/^\s*#/ and $_ =~ m/\S/} @config; + @config = grep { length($_) and $_ !~ m/^\s*#/ and $_ =~ m/\S/} + map {s/^\s+//; s/\s+$//; $_;} # trim leading/trailing whitespace + @config; close CF; my $pos = 0; diff --git a/t/config.t b/t/config.t index d71732c..2def46c 100644 --- a/t/config.t +++ b/t/config.t @@ -17,6 +17,11 @@ ok(my ($smtpd, $conn) = Test::Qpsmtpd->new_conn(), "get new connection"); is($smtpd->config('me'), 'some.host.example.org', 'config("me")'); +# test for ignoring leading/trailing whitespace (relayclients has a +# line with both) +my $relayclients = join ",", sort $smtpd->config('relayclients'); +is($relayclients, '127.0.0.1,192.168.', 'config("relayclients") are trimmed'); + unlink "./config.sample/me";