Skip to content

Commit

Permalink
Ignore leading/trailing whitespace in config files
Browse files Browse the repository at this point in the history
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
robert committed Jan 2, 2009
1 parent 4f6c3a6 commit 798eebc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -62,6 +62,8 @@
New config option "spool_perms" to set permissions of spool_dir New config option "spool_perms" to set permissions of spool_dir
(Jared Johnson) (Jared Johnson)


leading/trailing whitespace in config files is ignored (Henry Baragar)

0.43 - February 5, 2008 0.43 - February 5, 2008


(This release was mostly done by Matt Sergeant and Hanno Hecker) (This release was mostly done by Matt Sergeant and Hanno Hecker)
Expand Down
5 changes: 3 additions & 2 deletions config.sample/relayclients
@@ -1,4 +1,5 @@
# Format is IP, or IP part with trailing dot # Format is IP, or IP part with trailing dot
# e.g. "127.0.0.1", or "192.168." # e.g. "127.0.0.1", or "192.168."
127.0.0.1 127.0.0.1
192.168. # leading/trailing whitespace is ignored
192.168.
4 changes: 3 additions & 1 deletion lib/Qpsmtpd.pm
Expand Up @@ -239,7 +239,9 @@ sub _config_from_file {
open CF, "<$configfile" or warn "$$ could not open configfile $configfile: $!" and return; open CF, "<$configfile" or warn "$$ could not open configfile $configfile: $!" and return;
my @config = <CF>; my @config = <CF>;
chomp @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; close CF;


my $pos = 0; my $pos = 0;
Expand Down
5 changes: 5 additions & 0 deletions t/config.t
Expand Up @@ -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")'); 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"; unlink "./config.sample/me";




0 comments on commit 798eebc

Please sign in to comment.