Permalink
Browse files

Ignore leading/trailing whitespace in config files

Author: Henry Baragar <Henry.Baragar@instantiated.ca>


git-svn-id: http://svn.perl.org/qpsmtpd/trunk@966 958fd67b-6ff1-0310-b445-bb7760255be9
  • Loading branch information...
1 parent 4f6c3a6 commit 798eebcad8312cf56623a30bfaa7f8e28a009cca robert committed Jan 2, 2009
Showing with 13 additions and 3 deletions.
  1. +2 −0 Changes
  2. +3 −2 config.sample/relayclients
  3. +3 −1 lib/Qpsmtpd.pm
  4. +5 −0 t/config.t
View
@@ -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)
@@ -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.
View
@@ -239,7 +239,9 @@ sub _config_from_file {
open CF, "<$configfile" or warn "$$ could not open configfile $configfile: $!" and return;
my @config = <CF>;
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;
View
@@ -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";

0 comments on commit 798eebc

Please sign in to comment.