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 Joe Orton <jo...@redhat.com> on 2004/08/18 11:01:32 UTC
shell_ready function
Does the quote escaping really work in this function? It confuses emacs
font-lock mode which doesn't see a closing quote so thinks the rest of
the file is part of the string. This fixes at least the latter:
Index: TestConfig.pm
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestConfig.pm,v
retrieving revision 1.239
diff -u -r1.239 TestConfig.pm
--- TestConfig.pm 15 Aug 2004 23:19:57 -0000 1.239
+++ TestConfig.pm 18 Aug 2004 08:55:29 -0000
@@ -1754,7 +1754,7 @@
# escape quotes)
sub shell_ready {
my $arg = shift;
- $arg =~ s/"/\"/g;
+ $arg =~ s/"/\\"/g;
return qq["$arg"];
}
Re: shell_ready function
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> and here is the optimized version of Geoff's one:
>
> sub shell_ready_stas {
> my $arg = shift;
> $arg =~ s!\\?"!\\"!g;
> return qq["$arg"];
> }
>
> :)
Benchmark: timing 1000000 iterations of geoff, stas...
geoff: 64 wallclock secs (56.35 usr + 0.10 sys = 56.45 CPU) @
17714.79/s (n=1000000)
stas: 43 wallclock secs (40.27 usr + 0.06 sys = 40.33 CPU) @
24795.44/s (n=1000000)
/me bows to the master
--Geoff
Re: shell_ready function
Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
>
> Joe Orton wrote:
>
>>Does the quote escaping really work in this function?
>
>
> hmm, it doesn't look like it does. I think this was part of some work that
> stas and ken were doing, though, and IIRC it was some win32 command line
> thing. but I could be wrong.
>
>
>>It confuses emacs
>>font-lock mode which doesn't see a closing quote so thinks the rest of
>>the file is part of the string. This fixes at least the latter:
>
>
>>- $arg =~ s/"/\"/g;
>>+ $arg =~ s/"/\\"/g;
>
>
> that looks better, but I'm not sure it's right either - if the input is
> already escaped then you've (both) over-quoted (if the first worked at all,
> that is :) so, you look to be fine here if pre-quoted input is forbidden or
> not expected, but not so if it's already quoted, in which case something
> like this is better:
>
> $arg =~ s!([^\\])"!$1\\"!g;
>
> the attached script runs through a few different regex and input
> combinations for visual inspection. hopefully that will help sort this
> issue out a bit (or the original author will clear things up ;)
Yeah, I guess it's the best to ask Ken, it worked for him.
Jon's looks better, and Geoff's is even better,
I've checked CPAN and found
http://search.cpan.org/src/ROSCH/String-ShellQuote-1.00/ShellQuote.pm
but it probably is not what you are after, right?
Either way +1 to Geoff's version.
and here is the optimized version of Geoff's one:
sub shell_ready_stas {
my $arg = shift;
$arg =~ s!\\?"!\\"!g;
return qq["$arg"];
}
:)
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
Re: shell_ready function
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Joe Orton wrote:
> Does the quote escaping really work in this function?
hmm, it doesn't look like it does. I think this was part of some work that
stas and ken were doing, though, and IIRC it was some win32 command line
thing. but I could be wrong.
> It confuses emacs
> font-lock mode which doesn't see a closing quote so thinks the rest of
> the file is part of the string. This fixes at least the latter:
> - $arg =~ s/"/\"/g;
> + $arg =~ s/"/\\"/g;
that looks better, but I'm not sure it's right either - if the input is
already escaped then you've (both) over-quoted (if the first worked at all,
that is :) so, you look to be fine here if pre-quoted input is forbidden or
not expected, but not so if it's already quoted, in which case something
like this is better:
$arg =~ s!([^\\])"!$1\\"!g;
the attached script runs through a few different regex and input
combinations for visual inspection. hopefully that will help sort this
issue out a bit (or the original author will clear things up ;)
--Geoff