You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In case when semicolon is a part of CSS code, and CSS will be converted to JSON object, and JSON object converted back to CSS, the resulting CSS will be cut off after the semicolon.
I created a fix for this by allowing CSS's url "function" , these are the changes I did to get this problem fixed.
// Adding special handling for CSS function "url()" ( and format() if it follows url() ) - if detected,
// everything inside it (colons, semicolons etc.) should be treated as attribute value and not as delimiters.
// Changed are lineAttrX and altX regex, regex should also cover
// case when single CSS attribute breaks into more than one line.
I couldn't fork this project and create fix in library but here are steps anyone can replicate in library to fix their downloaded copy:
1 - In un-minified version find:
var lineAttrX = /([^\:]+):([^\;]*);/;
this should be replaced by:
var lineAttrX = /([^\:]+):(\s*url\([\s\S]+?\)|[^\;]*);/;
2 - In un-minified version find:
var altX = /(\/\*[\s\S]*?\*\/)|([^\s\;\{\}][^\;\{\}]*(?=\{))|(\})|([^\;\{\}]+\;(?!\s*\*\/))/gmi;
this should be replaced by:
var altX = /(\/\*[\s\S]*?\*\/)|([^\s\;\{\}][^\;\{\}]*(?=\{))|(\})|(\s*.*\:\s*url\([\s\S]+?\)\;(?!\s*\*\/)|[^\;\{\}]+\;(?!\s*\*\/))/gmi;
Version of library with replacements 1 and 2 should handle url() function correctly even if it contains semicolons, also if url() is followed by CSS function format() - this too will be included.
Also, if url() is in one line, and format() is in the line below, this too should be handled correctly.
In case when semicolon is a part of CSS code, and CSS will be converted to JSON object, and JSON object converted back to CSS, the resulting CSS will be cut off after the semicolon.
Error reproduction example, if CSS is:
src: url("data:application/octet-stream;base64,d09GRgABAAAAAAnwAA4AAA [SHORTENED] zAju/YGBgXX2kwJFwDEASgaAAAA") format("truetype");
after conversion to JSON and back to CSS, resulting CSS string will be:
src: url("data:application/octet-stream;
Example for Visual Studio Code with added cssjson npm package:
The text was updated successfully, but these errors were encountered: