Subject: | Empty blocks with trailing whitespace causes parsing failure |
My company is running a number of perl applications on Debian GNU/Linux
6.0.4 which comes with perl 5.10.1 installed - the perl version we use.
All our file configurations are loaded using Config::General version
2.48, and recently I encountered a problem with this module.
The problem manifested itself when someone entered an empty block into a
configuration file, e.g. <block/> or <block></block>, which caused the
module to croak with an error message of this kind
Block "<RootElement>" has no EndBlock statement
After reading through the documentation, which states that empty blocks
can be used, and running a number of tests, I discovered that if an
empty block has a trailing whitespace, Config::General fails to parse
and load the file, but if none of the empty blocks have trailing
whitespace - then all is fine.
I've attached two trimmed config files, one that is OK and one that will
fail, and a script for loading them both in succession. This illustrates
that just one tiny whitespace can cause the entire module to croak.
I've also tested this problem on Config::General version 2.51 and got
the same result, it failed on empty blocks with trailing whitespace.
Subject: | myconf.err |
Message body not shown because it is not plain text.
Subject: | conf_test.pl |
#!/usr/bin/perl -w
use v5.10;
use strict;
use Data::Dumper;
use Config::General qw{ParseConfig};
printf "[Using version %s of Config::General]\n", Config::General->VERSION;
for my $f ('myconf.ok', 'myconf.err') {
die "No such config file '$f'" unless -r $f;
say "Loading config from $f ...";
eval {
my %conf = ParseConfig(-ConfigFile => $f,
-BackslashEscape => 1,
-CComments => 0);
if (my $partner_conf = $conf{location}{partner}) {
printf "Successfully loaded config: %s\n", Dumper $partner_conf;
} else {
say "** Failed to load config from file '$f'";
}
};
say "** Encountered error loading file '$f': $@" if $@;
}
Subject: | myconf.ok |
Message body not shown because it is not plain text.