html-minifier icon indicating copy to clipboard operation
html-minifier copied to clipboard

ignoreCustomFragments do not ignore < inside regex match

Open FCO opened this issue 5 years ago • 4 comments

even doing ignoreCustomFragments: [ /\[%.*?%]/s ], it will not ignore < inside [% %]. or example:

[%
   IF 1 < 2
-%]
   BLA
[%- END %]

dies with:

[09:08:02] Error in plugin "gulp-htmlmin"
Message:
    Parse Error: < 2 -%] BLA	rqa14zm906f0		rqa14zm906f1 ...

(it must be related to the \n, because without it, it works)

[% IF 1 < 2 -%]
   BLA
[%- END %]

(this works, but please pay attention at the s flag on the regex)

FCO avatar Jun 22 '20 09:06 FCO

using the regex /\[%[\s\S]*?%]/ it works. Why the s flag isn't working?

FCO avatar Jun 22 '20 09:06 FCO

\s is any whitespace character \S is any non-whitespace character

You can test regular expressions at https://regex101.com/

DanielRuf avatar Jul 25 '20 14:07 DanielRuf

Yes, I know. But . wit the s flag should match anything, including \n, so /[\s\S]/ and /./s should be equivalent, so, my version should work, shouldn't it?

FCO avatar Aug 06 '20 05:08 FCO

I think we should debug this in detail. In general it should be .* or .+ as a qualifier is needed. Plus \s if relevant.

DanielRuf avatar Aug 06 '20 06:08 DanielRuf