Bug 11793

Summary: Parse error in ExtFilterDefine
Product: Apache httpd-2 Reporter: Sebastian Wolfgarten <sebastian.wolfgarten>
Component: mod_ext_filterAssignee: Apache HTTPD Bugs Mailing List <bugs>
Status: CLOSED FIXED    
Severity: normal    
Priority: P3    
Version: 2.0.40   
Target Milestone: ---   
Hardware: PC   
OS: Linux   

Description Sebastian Wolfgarten 2002-08-17 18:04:28 UTC
Hello,

I'm currently playing with output
filters. I thought of using awk
to print out the number
of each line. In my bash shell I
used this:

echo "<html>" | awk '{print NR ":" $N}'

I add the following lines to my httpd.conf:

ExtFilterDefine awk_line_numbering mode=output outtype=text/html 
cmd="/bin/awk '{print NR\": \" $N}'" 
<Location /> 
SetOutputFilter awk_line_numbering 
</Location>

Now when I start the apache I get a
syntax error. 

Unexpected parameter: `: \" $N}'"'

I suppose this is a bug because some
external programs like awk need to use
quotation marks in order to work.
A workaround is to put the awk command in
an extra shell script but I assume
this to be a bug.

My friend Werner Schalk has already posted
this to the users mailing list of apache but
they said I should use back-slashes (what I
did anyway) or to report a bug. Here it is :-)

Bye and thanks,
Sebastian Wolfgarten
Comment 1 William A. Rowe Jr. 2002-08-18 20:01:48 UTC
Did you try
  ExtFilterDefine awk_line_numbering mode=output outtype=text/html 
     cmd="/bin/awk '{print NR\\\": \\\" $N}'"

In case the '\' escaping is eating the second double quote?

If that's not the workaround, there is a bug in the parser.
Comment 2 Paul J. Reder 2002-08-19 16:26:00 UTC
This indeed seems to be a bug. parse_cmd in mod_ext_filter.c does not process
escaping characters. It sees the first " and scans till it finds the next ". No
checks for escape chars.

I'll have a fix shortly.
Comment 3 Christoph Vogel 2002-08-19 20:44:38 UTC
If you need a line numbering ExtFilter urgently you can use pr without getting 
into escaping issues:

ExtFilterDefine pr_line_numbering cmd="/usr/bin/pr -n -t"
Comment 4 Jeff Trawick 2002-08-21 19:57:22 UTC
This was fixed earlier today (go Paul!).  I just verified that this 
cmd= parameter yields a filter that prefixes the response with line 
numbers:

cmd="/bin/awk '{print NR\": \" $N}'"

To pick up the fix, you need a new modules/experimental/mod_ext_filter.c 
and a new srclib/apr/strings/apr_cpystrn.c.  This will all be in the 
next release of Apache 2.0.x.

Thanks for your report, and thanks for using Apache.
Comment 5 Jeff Trawick 2002-08-21 20:19:58 UTC
*** Bug 11794 has been marked as a duplicate of this bug. ***