cminify icon indicating copy to clipboard operation
cminify copied to clipboard

Doesn't care about whitespace inside string literals

Open catb0t opened this issue 7 years ago • 5 comments

"a: %d %d %d\n"

becomes

"a:%d%d%d\n"

oops.

catb0t avatar Jun 28 '17 13:06 catb0t

It is intended that string literals stay untouched. I followed this bug into the function minify_operator(op). There is the regex / *{} */ used (where {} in the regex was replaced with one of the elements of OPS) to strip down spaces around operators.

The problem is that every occurrence of that is replaced regardless of its context (inside or outside of a string literal).

It may be possible to extend this regex. In my opinion it would be easier no to use a regex and additionally process the whole file at once instead the lines one after the other (iterating over an array). Think of this code snippet:

"hello \
world\
 &"

If a regex is used it would required to count the number of occurrences " or test, if the last character of a line is backslash in order to know if the context is a string literal.

I'm contributing hereby some knowledge, but my Python skills not good enough to rewrite the broken function.

I apologize for my English and some phrases that could be expressed better. I hope you get the point. :-)

Arlon1 avatar Jul 24 '17 18:07 Arlon1

I think it wouldn't be too hard extending the regex to exclude everything between a potential couple of quotes (") that aren't in a comment but I won't have time to look into that before some weeks at least.

Still it's an important bug to fix.

Scylardor avatar Jul 25 '17 12:07 Scylardor

so no fix there?

maxsupermanhd avatar Mar 15 '20 22:03 maxsupermanhd

Hello, sorry, I'm being overworked with other research projects right now but I am aware of all the issues with this project. I'll try to focus on the minifier for a week or two this summer to address all these problems. But these days I can't just yet. :-(

Cheers

Scylardor avatar Mar 20 '20 21:03 Scylardor

Waiting for you...

maxsupermanhd avatar Mar 20 '20 21:03 maxsupermanhd