#StackBounty: #apache-http-server #sed mod_sed – apache+sed – problems with backslash

Bounty: 50

I have just started using sed and are having a problem when using sed from Apache mod_seq.
The task is to change a web service post to a file upload post. Content-Type has already been changed using mod_headers and the task here is to change request body.

Request body:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://tracx.de/pkp/interfaces/msg/1.0" xmlns:ns1="http://tracx.de/pkp/interfaces/core/1.0"><soapenv:Header/><soapenv:Body><ns:test>Hello World</ns:test></soapenv:Body></soapenv:Envelope>

1) ok test with sed from command prompt:

sed "s/^.*$/--AaB03xnContent-disposition: form-data; name="xmlfile"; filename="myfile.xml"nContent-Type: text/xmlnn&n--AaB03x--n/" request.xml

Output as expected with newlines:

--AaB03x
Content-disposition: form-data; name="xmlfile"; filename="myfile.xml"
Content-Type: text/xml

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://tracx.de/pkp/interfaces/msg/1.0" xmlns:ns1="http://tracx.de/pkp/interfaces/core/1.0"><soapenv:Header/><soapenv:Body><ns:test>Hello World</ns:test></soapenv:Body></soapenv:Envelope>
--AaB03x--

2) Sed call with Apache mod_sed:

InputSed "s/^.*$/--AaB03xnContent-disposition: form-data; name="xmlfile"; filename="myfile.xml"nContent-Type: text/xmlnn&n--AaB03x--n/"

Output from mod_sed when request enters my web app. Note “n” instead of newline.

--AaB03xnContent-disposition: form-data; name="xmlfile"; filename="myfile.xml"nContent-Type: text/xmlnn<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://tracx.de/pkp/interfaces/msg/1.0" xmlns:ns1="http://tracx.de/pkp/interfaces/core/1.0"><soapenv:Header/><soapenv:Body><ns:test>monday</ns:test></soapenv:Body></soapenv:Envelope>n--AaB03x--n

I have tried with ” and “” i InputSed command. And tried with 1, 2, 3 and 4 backspaces before my control characters (r and n). It looks like Apache or mod_sed are ignoring backslash character.

Anyone that known if there is some special problems with mod_sed and backslash?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.