Skip to content

Commit

Permalink
Merge branch '7.1' into 7.2
Browse files Browse the repository at this point in the history
* 7.1:
  [FrameworkBundle] Add missing `not-compromised-password` entry in XSD
  [AssetMapper] Fix CssCompiler matches url in comments
  Add support for doctrine/persistence 4
  Ensure TransportExceptionInterface populates stream debug data
  Fix typo in validators.sk.xlf
  [Mime] Fix body validity check in `Email` when using `Message::setBody()`
  Review Arabic translations for the validator
  Fixed mistakes in proper hebrew writing in the previous translation and confirmed the rest to be correct and in the same style.
  Review translation
  [Cache] Don't clear system caches on cache:clear
  [FrameworkBundle] Fix patching refs to the tmp warmup dir in files generated by optional cache warmers
  Mark Czech Validator translation as reviewed
  [PropertyInfo] Fix `TypeTest` duplicated assert
  [Validator] Fix `Url` constraint attribute assertion
  convert legacy types to TypeInfo types if getType() is not implemented
  [HtmlSanitizer] Avoid accessing non existent array key when checking for hosts validity
  Update validators.ar.xlf
  [DomCrawler] Make `ChoiceFormField::isDisabled` return `true` for unchecked disabled checkboxes
  • Loading branch information
xabbuh committed Jan 27, 2025
2 parents 55461cf + f30a773 commit d9a514c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
27 changes: 26 additions & 1 deletion Compiler/CssAssetUrlCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,32 @@ public function __construct(

public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string
{
return preg_replace_callback(self::ASSET_URL_PATTERN, function ($matches) use ($asset, $assetMapper) {
preg_match_all('/\/\*|\*\//', $content, $commentMatches, \PREG_OFFSET_CAPTURE);

$start = null;
$commentBlocks = [];
foreach ($commentMatches[0] as $match) {
if ('/*' === $match[0]) {
$start = $match[1];
} elseif ($start) {
$commentBlocks[] = [$start, $match[1]];
$start = null;
}
}

return preg_replace_callback(self::ASSET_URL_PATTERN, function ($matches) use ($asset, $assetMapper, $commentBlocks) {
$matchPos = $matches[0][1];

// Ignore matchs inside comments
foreach ($commentBlocks as $block) {
if ($matchPos > $block[0]) {
if ($matchPos < $block[1]) {
return $matches[0][0];
}
break;
}
}

try {
$resolvedSourcePath = Path::join(\dirname($asset->sourcePath), $matches[1]);
} catch (RuntimeException $e) {
Expand Down
30 changes: 30 additions & 0 deletions Tests/Compiler/CssAssetUrlCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,36 @@ public static function provideCompileTests(): iterable
'expectedOutput' => 'body { background: url("https://cdn.io/images/bar.png"); }',
'expectedDependencies' => [],
];

yield 'ignore_comments' => [
'input' => 'body { background: url("images/foo.png"); /* background: url("images/bar.png"); */ }',
'expectedOutput' => 'body { background: url("images/foo.123456.png"); /* background: url("images/bar.png"); */ }',
'expectedDependencies' => ['images/foo.png'],
];

yield 'ignore_comment_after_rule' => [
'input' => 'body { background: url("images/foo.png"); } /* url("images/need-ignore.png") */',
'expectedOutput' => 'body { background: url("images/foo.123456.png"); } /* url("images/need-ignore.png") */',
'expectedDependencies' => ['images/foo.png'],
];

yield 'ignore_comment_within_rule' => [
'input' => 'body { background: url("images/foo.png") /* url("images/need-ignore.png") */; }',
'expectedOutput' => 'body { background: url("images/foo.123456.png") /* url("images/need-ignore.png") */; }',
'expectedDependencies' => ['images/foo.png'],
];

yield 'ignore_multiline_comment_after_rule' => [
'input' => 'body {
background: url("images/foo.png"); /*
url("images/need-ignore.png") */
}',
'expectedOutput' => 'body {
background: url("images/foo.123456.png"); /*
url("images/need-ignore.png") */
}',
'expectedDependencies' => ['images/foo.png'],
];
}

public function testCompileFindsRelativeFilesViaSourcePath()
Expand Down

0 comments on commit d9a514c

Please sign in to comment.