You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-dev@httpd.apache.org by Stas Bekman <st...@stason.org> on 2001/12/23 17:43:26 UTC

[patch] better failure diagnostics for config token substitution

if the config token get mistyped, e.g. @servrename@ the current replace()
sub will simply die without helping to locate which token is unknown to
Apache-Test. This patch reports the offensive token (of course it'd be
nice to tell which file it comes from but the current implementation
doesn't allow that)

Index: Apache-Test/lib/Apache/TestConfig.pm
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestConfig.pm,v
retrieving revision 1.117
diff -u -r1.117 TestConfig.pm
--- Apache-Test/lib/Apache/TestConfig.pm	2001/12/21 12:44:16	1.117
+++ Apache-Test/lib/Apache/TestConfig.pm	2001/12/23 16:36:50
@@ -755,7 +755,12 @@

 sub replace {
     my $self = shift;
-    s/@(\w+)@/$self->{vars}->{lc $1}/g;
+    s[@(\w+)@]
+     [ my $key = lc $1;
+      exists $self->{vars}->{$key}
+      ? $self->{vars}->{$key}
+      : die qq{cannot substitute "\@$key\@" token}
+     ]ge;
 }

 #need to configure the vhost port for redirects and $ENV{SERVER_PORT}

we could do simpler:

+    s[@(\w+)@]
+     [ $self->{vars}->{lc $1}
+       || die qq{cannot substitute "\@$1\@" token}
+     ]ge;

But the value can be false (while valid), so it won't work for all cases.

_____________________________________________________________________
Stas Bekman             JAm_pH      --   Just Another mod_perl Hacker
http://stason.org/      mod_perl Guide   http://perl.apache.org/guide
mailto:stas@stason.org  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


Re: [patch] better failure diagnostics for config token substitution

Posted by Doug MacEachern <do...@covalent.net>.
On Mon, 24 Dec 2001, Stas Bekman wrote:

> if the config token get mistyped, e.g. @servrename@ the current replace()
> sub will simply die without helping to locate which token is unknown to
> Apache-Test. This patch reports the offensive token (of course it'd be
> nice to tell which file it comes from but the current implementation
> doesn't allow that)

+1

filename would be nice.  local $Apache::TestConfig::File or similar in
generate_extra_conf would get most of them.