Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with semicolon in function "moveImportsToTop" #289

Open
SventB opened this issue Aug 7, 2019 · 2 comments
Open

Problems with semicolon in function "moveImportsToTop" #289

SventB opened this issue Aug 7, 2019 · 2 comments

Comments

@SventB
Copy link

SventB commented Aug 7, 2019

There's a problem with function "moveImportsToTop":
If it converts following CSS:

@charset "UTF-8";@import url(//fast.fonts.net/t/1.css?apiType=...);.aa{display:block}

The resulting (invalid) CSS is this:

@import url(//fast.fonts.net/t/1.css?apiType=...);@charset "UTF-8".aa{display:block}

This is invalid: "UTF-8".aa

It seems the problem is the (;?) in the regex:

preg_match_all('/(;?)(@import (?<url>url\()?(?P<quotes>["\']?).+?(?P=quotes)(?(url)\)));?/', $content, $matches)

This results in $matches[0]:

array(1) { [0]=> string(98) ";@import url(//fast.fonts.net/t/1.css?apiType=...);" }

The prefixed semicolon seems wrong.

@mhdhamouday
Copy link

mhdhamouday commented Jan 2, 2020

I have the same problem. I solved it using:
$Data_CSS = preg_replace('/@charset "(.*?)"/','@charset "$1";', $Data_CSS);

@phinor
Copy link

phinor commented Mar 28, 2024

As of version 1.3.73, this remains an issue.

@charset "UTF-8";
@import 'https://fonts.googleapis.com/css?family=Open+Sans:300,400italic,400,700';
:root {
  --max-width: 1280px;
}

minifies to become:

@import "https://fonts.googleapis.com/css?family=Open+Sans:300,400italic,400,700";@charset "UTF-8":root{--max-width:1280px;}

which invalidates the :root element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants