mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-10 05:52:13 +09:00
Fix #1868 incorrect parsing of CSS/SCSS import containing special characters
This commit is contained in:
parent
7e922cf2bc
commit
cb9f3dd1db
9 changed files with 56 additions and 19 deletions
|
|
@ -351,12 +351,17 @@ class Formatter
|
|||
$content = utf8_clean(file_get_contents($filename));
|
||||
|
||||
// Convert all paths in LESS and SCSS imports, too.
|
||||
$dirname = dirname($filename);
|
||||
$import_type = ends_with('.scss', $filename) ? 'scss' : 'normal';
|
||||
$content = preg_replace_callback('/@import\s+(?:\\([^()]+\\))?([^;]+);/', function($matches) use($filename, $target_filename, $import_type, &$imported_list) {
|
||||
$content = preg_replace_callback('/@import\s+([^\r\n]+);(?=[\r\n$])/', function($matches) use($dirname, $filename, $target_filename, $import_type, &$imported_list) {
|
||||
if (preg_match('!^url\([\'"]?((?:https?:)?//[^()\'"]+)!i', $matches[1], $urlmatches))
|
||||
{
|
||||
return '@import url("' . escape_dqstr($urlmatches[1]) . '");';
|
||||
}
|
||||
$import_content = '';
|
||||
$import_files = array_map(function($str) use($filename, $import_type) {
|
||||
$str = trim(trim(trim(preg_replace('/^url\\(([^()]+)\\)$/', '$1', trim($str))), '"\''));
|
||||
if (preg_match('!^(https?:)?//!i', $str))
|
||||
$import_files = array_map(function($str) use($dirname, $filename, $import_type) {
|
||||
$str = trim(trim(trim(preg_replace('!^url\([\'"]?([^()\'"]+)[\'"]?\)!i', '$1', $str)), '"\''));
|
||||
if (preg_match('!^(?:https?:)?//!i', $str))
|
||||
{
|
||||
return $str;
|
||||
}
|
||||
|
|
@ -369,7 +374,7 @@ class Formatter
|
|||
{
|
||||
$basename = '_' . $basename . '.scss';
|
||||
}
|
||||
return dirname($filename) . '/' . substr($str, 0, $dirpos) . '/' . $basename;
|
||||
return $dirname . '/' . substr($str, 0, $dirpos) . '/' . $basename;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -378,7 +383,7 @@ class Formatter
|
|||
{
|
||||
$basename = '_' . $basename . '.scss';
|
||||
}
|
||||
return dirname($filename) . '/' . $basename;
|
||||
return $dirname . '/' . $basename;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -388,22 +393,19 @@ class Formatter
|
|||
}, explode(',', $matches[1]));
|
||||
foreach ($import_files as $import_filename)
|
||||
{
|
||||
if (!preg_match('!^(https?:)?//!i', $import_filename))
|
||||
if (preg_match('!^(https?:)?//!i', $import_filename))
|
||||
{
|
||||
if (file_exists($import_filename))
|
||||
{
|
||||
$imported_list[] = $import_filename;
|
||||
$import_content .= self::concatCSS($import_filename, $target_filename, false, $imported_list);
|
||||
}
|
||||
else
|
||||
{
|
||||
$error_filename = substr($import_filename, strlen(\RX_BASEDIR));
|
||||
trigger_error('Imported file not found: ' . $error_filename, \E_USER_WARNING);
|
||||
}
|
||||
$import_content .= '@import url("' . escape_dqstr($import_filename) . '");';
|
||||
}
|
||||
elseif (file_exists($import_filename))
|
||||
{
|
||||
$imported_list[] = $import_filename;
|
||||
$import_content .= self::concatCSS($import_filename, $target_filename, false, $imported_list);
|
||||
}
|
||||
else
|
||||
{
|
||||
$import_content .= '@import url("' . escape_dqstr($import_filename) . '");';
|
||||
$error_filename = substr($import_filename, strlen(\RX_BASEDIR));
|
||||
trigger_error('Imported file not found: ' . $error_filename, \E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
return trim($import_content);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
$setting: 5px;
|
||||
|
||||
@import url('//fonts.googleapis.com/css?family=Raleway:700,400');
|
||||
@import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700;1,400;1,700&display=swap');
|
||||
|
||||
@mixin mymixin($size) {
|
||||
margin: $size;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
@import 'scss/include1.scss';
|
||||
@import url('scss/include2.scss');
|
||||
@import 'scss/partial1', 'scss/partial2';
|
||||
|
||||
.rhymix {
|
||||
color: $foo;
|
||||
background: url('foo/bar.jpg');
|
||||
|
|
|
|||
|
|
@ -1,6 +1,20 @@
|
|||
@charset "UTF-8";
|
||||
/* Original file: tests/_data/formatter/scss.source1.scss */
|
||||
@import url("//fonts.googleapis.com/css?family=Raleway:700,400");
|
||||
@import url("https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700;1,400;1,700&display=swap");
|
||||
/* Original file: tests/_data/formatter/scss.source2.scss */
|
||||
.inc1 {
|
||||
margin: 5px;
|
||||
}
|
||||
.inc2 {
|
||||
padding-left: 10px;
|
||||
}
|
||||
.partial1 {
|
||||
display: flex;
|
||||
}
|
||||
.partial2 {
|
||||
display: none;
|
||||
}
|
||||
.rhymix {
|
||||
color: #123456;
|
||||
background: url("../_data/formatter/foo/bar.jpg");
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
@charset "UTF-8";
|
||||
.rhymix{color:#123456;background:url("../_data/formatter/foo/bar.jpg")}.rhymix span{margin:320px}
|
||||
@import url("//fonts.googleapis.com/css?family=Raleway:700,400");@import url("https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700;1,400;1,700&display=swap");.inc1{margin:5px}.inc2{padding-left:10px}.partial1{display:flex}.partial2{display:none}.rhymix{color:#123456;background:url("../_data/formatter/foo/bar.jpg")}.rhymix span{margin:320px}
|
||||
|
|
|
|||
3
tests/_data/formatter/scss/_partial1.scss
Normal file
3
tests/_data/formatter/scss/_partial1.scss
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.partial1 {
|
||||
display: flex;
|
||||
}
|
||||
3
tests/_data/formatter/scss/_partial2.scss
Normal file
3
tests/_data/formatter/scss/_partial2.scss
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.partial2 {
|
||||
display: none;
|
||||
}
|
||||
3
tests/_data/formatter/scss/include1.scss
Normal file
3
tests/_data/formatter/scss/include1.scss
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.inc1 {
|
||||
margin: $setting;
|
||||
}
|
||||
3
tests/_data/formatter/scss/include2.scss
Normal file
3
tests/_data/formatter/scss/include2.scss
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.inc2 {
|
||||
padding-left: $setting * 2;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue