pyminifier icon indicating copy to clipboard operation
pyminifier copied to clipboard

The multiline_indicator allows comments after a line-continuating backslash

Open blikjeham opened this issue 9 years ago • 0 comments

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.

  • https://docs.python.org/3/reference/lexical_analysis.html#explicit-line-joining

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).

blikjeham avatar Feb 24 '17 15:02 blikjeham