Home > other >  How to replace string with a string having space characters in substitution part of mod_substitute
How to replace string with a string having space characters in substitution part of mod_substitute

Time:08-30

In my apache 2.4 httpd server, I want to add this small javascript snippet in my response using mod_substitute.

Like this -

     <Location /styles.blahblah.css>
            AddOutputFilterByType Substitute text/css
            Substitute s|::-webkit-scrollbar{width:16px}|'.button-group :first-child{display:none}::-webkit-scrollbar{width:16px}'|ni
    </Location>

But the problem is that this gives compilation error due to the space after button-group in the substitution part. If I remove the space it compiles, but that is not what I want.

I tried to define a variable and used that in the substitution part, but it results in same error if the variable too has space. It does not throw error if I remove the space from the variable.

    Define css_substitution ".button-group :first-child{display:none}::-webkit-scrollbar{width:16px}"

     <Location /styles.blahblah.css>
            AddOutputFilterByType Substitute text/css
            Substitute s|::-webkit-scrollbar{width:16px}|${css_substitution}|ni
    </Location>

Is there a way to have a space character in the substitution part in mod_substitute. The documentation nowhere says we cannot have space char in substitution.

CodePudding user response:

I was able to achieve this by surrounding the whole Substitute statement in double quotes like this -

 <Location /styles.blahblah.css>
        AddOutputFilterByType Substitute text/css
        Substitute "s|::-webkit-scrollbar{width:16px}|'.button-group :first-child{display:none}::-webkit-scrollbar{width:16px}'|i"
</Location>
  • Related