liftoff / pyminifier

Pyminifier is a Python code minifier, obfuscator, and compressor.
GNU General Public License v3.0
1.45k stars 223 forks source link

The multiline_indicator allows comments after a line-continuating backslash #84

Open blikjeham opened 7 years ago

blikjeham commented 7 years ago

The multiline_indicator regex is '\\\\(\s*#.*)?\n'. This would allow a comment after a backslash used for explicit line joining, like:

if a == b \  # a equals b
        and b == c:
    pass

The above is not valid python syntax:

A line ending in a backslash cannot carry a comment.

Even worse, the multiline_indicator regex also sees a line continuation with comment in the following regex from HamlPy:

'(?P<id>\#[\w-]*)?'

This breaks minifying code with similar regexes.

I think the multiline_indicator should only look for lines ending in only a backslash (and perhaps some whitespace).