Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: How To Insert Carriage Returns When Using Substitute Command |
|
Author |
|
apishdad
Joined: 01 Jul 2019 Posts: 52 Location: Canada, Toronto
|
Posted: Fri 14 Feb '25 10:21 Post subject: How To Insert Carriage Returns When Using Substitute Command |
|
|
Hi,
I have a situation where in the final output I need to have the lines separated.
Lets say you have a substitute command as follows :
Substitute "s#</head>#<script> alert('Testing') </script></head#inq"
This will result in the final output as
<script> alert('Testing') </script></head>
But I want it to show as
<script>
alert('Testing')
</script>
</head>
How do I do that ?
Your response is greatly appreciated. |
|
Back to top |
|
tangent Moderator
Joined: 16 Aug 2020 Posts: 362 Location: UK
|
Posted: Tue 18 Feb '25 16:57 Post subject: |
|
|
I've never has any success with inserting non-printing characters using mod_substitute.
Back in the days of Apache 2.2 series, someone did develop a mod_substitute variant that supported using environment variables, and I used that for several years to good effect. Unfortunately though, that code never got consolidated into Apache nor converted to work with 2.4 series mod_substitute, nor do I have a record of who created that variant.
Having said that, I still have a 2.2 series patch file for that version of mod_substitute.c tucked away, should you wish to take up the challenge.
I note the mod_substitute documentation for Apache 2.5 makes mention of using an expression construct, "expr=", and that code is included in the GitHub HTTPD trunk, but as yet that's not found its way into the 2.4 releases.
However, having compiled that updated module with the rest of the 2.4.63 source release, I can confirm you can use an expression to insert newlines in a replacement string, e.g.
Code: | Substitute "s@(<head>)@expr=\$1\n<script>\nalert('Testing')\n</script>\n@iq |
This produces what you said you wanted, viz:
<head>
<script>
alert('Testing')
</script>
</head>
Note, expr= must be at the start of the replacement string to be recognised.
If you really need this feature at the moment, you could compile up the module using the HOWTO: Building Apache and dependencies with CMake. |
|
Back to top |
|
apishdad
Joined: 01 Jul 2019 Posts: 52 Location: Canada, Toronto
|
Posted: Tue 18 Feb '25 17:21 Post subject: |
|
|
Thanks Tangent, as always one of the best in this lounge.
I appreciate the fact that you mentioned we cant do it in 2.4. Unfortunately its not my company and I rather not implement a customization because then across many servers it becomes a chore to make sure everyone follows the standard, and there is already lots of work here. But noted what you mentioned I think the better thing to suggest to my boss is to upgrade the entire Apaches to 2.5 |
|
Back to top |
|
tangent Moderator
Joined: 16 Aug 2020 Posts: 362 Location: UK
|
Posted: Tue 18 Feb '25 17:46 Post subject: |
|
|
Apache 2.5 isn't officially released yet, so I'd hang fire on that suggestion. |
|
Back to top |
|
|
|
|
|
|