NV / CSSOM

Unmaintained! ⚠️ CSS Object Model implemented in pure JavaScript. Also, a CSS parser.
https://nv.github.io/CSSOM/docs/parse.html
MIT License
752 stars 99 forks source link

")" not found when trying to import font with multiple weights #116

Open RahulLanjewar93 opened 1 year ago

RahulLanjewar93 commented 1 year ago

https://github.com/NV/CSSOM/blob/a469aae2f92e454e669aec821781626924f98d17/lib/parse.js#L333-L358

This fails for import rules for fonts which have multiple font weights.

Example :- @import url(https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@300;400&display=swap);

I get the error:- ")" not found. I am guessing it's due to semicolon being encountered first before closing the bracket.

RahulLanjewar93 commented 1 year ago

@papandreou @NV Any idea how we can resolve this?

papandreou commented 1 year ago

Yeah, looks like the parser doesn't handle semicolons within url(...).

One possible workaround is to add quotes around the url:

@import url('https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@300;400&display=swap');

Or you can percent-encode the semicolon:

@import url(https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@300%3B400&display=swap);
RahulLanjewar93 commented 1 year ago

Thanks for the workaround.