Ok so I am modifying my body output to include some added text inside of one of my _javascript_ html tags. But unfortunately it is not working because my regex is bad (really bad) and I can't actually figure out the correct and most universal / compatible way to NOT end up removing the _javascript_ contents completely i want to pass the contents to %1 and re-insert it.
Here is what I put together that would work if my regex was right and i knew what regex i actually need to be using.
Lua code body_filter_by_lua_block :
local body = ngx.arg[1] --Put body into local var
local _javascript_valuetable = {
{ --Login page
"<script type=\"text/_javascript_\">", --HTML to find Start
"%1\n/* now this is here */", --Replace with
"(.-)", --Regex to match
"</script>", --HTML to find End
"<!-- modifyme -->", --Look between these tags
},
}
for key, val in pairs (_javascript_valuetable) do
local string_match = ngx.re.match(body, val[1] .. val[3] .. val[4]) --Search through body to see if our html match is found
if string_match then --If not empty
body = ngx.re.gsub(body, val[1] .. val[3] ..val[4], val[1] .. val[2] .. val[4])
ngx.arg[1] = body
end
end
HTML Body to be modified :
<!-- modifyme -->
<script type="text/_javascript_">
(function(){
alert("I am an alert box!");
})();
</script>
<!-- modifyme -->
What the output i am trying to achieve / get is : (modify me tags removed and my text inserted)
<script type="text/_javascript_">
(function(){
alert("I am an alert box!");
})();
/* now this is here */
</script>