jotform / css.js

A lightweight, battle tested, fast, CSS parser in JavaScript
https://medium.com/jotform-form-builder/writing-a-css-parser-in-javascript-3ecaa1719a43
MIT License
426 stars 63 forks source link

Fix one RegExp for parsing "@import" method correctly. #32

Closed 7happy7 closed 3 years ago

7happy7 commented 4 years ago

new RegExp('@import .*?;','gi') cannot parse some Google Fonts' URL:

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,400;1,300&display=swap');

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,400;

This bug can be fixed by changing the RegExp to new RegExp('@import (?:url\\(.*?\\)|).*?;','gi') (/@import (?:url\(.*?\)|).*?;/gi).