ThisIsManta / stylus-supremacy

A Node.js script that helps formatting Stylus files.
https://thisismanta.github.io/stylus-supremacy
MIT License
88 stars 9 forks source link

Problem with unescaped quote characters #15

Closed exdeniz closed 6 years ago

exdeniz commented 6 years ago

Bug on line like this

background-image url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='30' height='30' viewBox='0 0 30 30'> <circle cx='15' cy='15' r='14' fill='none' stroke='#3c3c3c' stroke-width='1'/> </svg>")

after format

background-image url('data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='30' height='30' viewBox='0 0 30 30'> <circle cx='15' cy='15' r='14' fill='none' stroke='#3c3c3c' stroke-width='1'/> </svg>')

setting supremacy

"stylusSupremacy.insertColons": false,
  "stylusSupremacy.insertSemicolons": false,
  "stylusSupremacy.insertBraces": false,
  "stylusSupremacy.insertNewLineBetweenSelectors": true,
  "stylusSupremacy.insertLeadingZeroBeforeFraction": false,
  "stylusSupremacy.alwaysUseImport": true,
  "stylusSupremacy.alwaysUseZeroWithoutUnit": true,
  "stylusSupremacy.reduceMarginAndPaddingValues": false,
  "stylusSupremacy.insertNewLineAroundBlocks": "root",
  "stylusSupremacy.insertNewLineAroundProperties": false,
  "stylusSupremacy.insertNewLineAroundOthers": "root",
  "stylusSupremacy.sortProperties": [
    "lost-column",
    "lost-flex",
     ...
  ],
ThisIsManta commented 6 years ago

Does it have something to do with single/double quote conversion?

exdeniz commented 6 years ago

Yes, inline svg need use single. and see first quote after url(

background-image url(''data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='30' height='30' viewBox='003030'> <circle cx='15' cy='15' r='14' fill='none' stroke='#3c3c3c' stroke-width='1'/> </svg>'') // www.w3.org/2000/svg' width='30' height='30' viewBox='0 0 30 30'> <circle cx='15' cy='15' r='14' fill='none' stroke='#3c3c3c' stroke-width='1'/> </svg>')
exdeniz commented 6 years ago

May be can add comment line before like // supremacy disable Formatter work is correct, this is particular case.

ThisIsManta commented 6 years ago

I think this is an exception for single-quote users. The formatter must not converting double to single quotes for url("data:image/svg+xml;utf8,<svg>....</svg>"). I'll make a patch for that real quick.

ThisIsManta commented 6 years ago

Here's the solution:

  1. If the string starts with data:image/svg+xml;utf8,, then it will convert the outer quote chars normally and also inverse the quotes in the content (single to double or vice versa, if needed.) See background-image
  2. If the string contains the target quote char, do not convert the quotes at all. See var1
  3. Otherwise, convert the outer most quote chars (normal behavior). See var2

For example, image

ThisIsManta commented 6 years ago

This is fixed in version 2.6.0.

Cheers!

exdeniz commented 6 years ago

Thank you for fix, it was really fast!