Skip to content

Commit

Permalink
fix left trim for the initial sub selector
Browse files Browse the repository at this point in the history
  • Loading branch information
overclokk committed Apr 20, 2024
1 parent 14ceb02 commit 94a9304
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Domain/Input/Styles/Css.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public function parseString(string $css, string $selector = ''): string
private function duplicateRulesForSelectorList(string $css): string
{
$pattern = '/\{(.*)}/s';
// $pattern = '/\s*\{([^}]*)}\s*/';
\preg_match($pattern, $css, $matches);

if (!isset($matches[1])) {
Expand All @@ -89,7 +88,7 @@ private function duplicateRulesForSelectorList(string $css): string
return $css;
}

$selectors = \trim(\substr($css, 0, $pos));
$selectors = \substr($css, 0, $pos);
$selectorArray = \explode(',', $selectors);

if (\count($selectorArray) === 1) {
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/Domain/Input/Styles/CssTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ public static function styleProvider(): iterable
'expected' => " .one {\ncolor: red;\n}\n& .two {\ncolor: red;\n}\n& .three {\ncolor: red;\n}\n",
// phpcs:enable
];

yield 'with list selectors and new line without original selector' => [
// phpcs:disable
'selector' => '',
'original' => " .one,& .two,& .three{\ncolor: red;\n}",
'expected' => " .one {\ncolor: red;\n}\n& .two {\ncolor: red;\n}\n& .three {\ncolor: red;\n}\n",
// phpcs:enable
];
}

/**
Expand Down

0 comments on commit 94a9304

Please sign in to comment.