Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e4ff4f1

Browse filesBrowse files
committed
Ignore matches inside comments
1 parent 076462d commit e4ff4f1
Copy full SHA for e4ff4f1

File tree

1 file changed

+26
-1
lines changed
Filter options

1 file changed

+26
-1
lines changed

‎src/Symfony/Component/AssetMapper/Compiler/CssAssetUrlCompiler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/AssetMapper/Compiler/CssAssetUrlCompiler.php
+26-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,32 @@ public function __construct(
3535

3636
public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string
3737
{
38-
return preg_replace_callback(self::ASSET_URL_PATTERN, function ($matches) use ($asset, $assetMapper) {
38+
preg_match_all('/\/\*|\*\//', $content, $commentMatches, \PREG_OFFSET_CAPTURE);
39+
40+
$start = null;
41+
$commentBlocks = [];
42+
foreach ($commentMatches[0] as $match) {
43+
if ('/*' === $match[0]) {
44+
$start = $match[1];
45+
} elseif ($start) {
46+
$commentBlocks[] = [$start, $match[1]];
47+
$start = null;
48+
}
49+
}
50+
51+
return preg_replace_callback(self::ASSET_URL_PATTERN, function ($matches) use ($asset, $assetMapper, $commentBlocks) {
52+
$matchPos = $matches[0][1];
53+
54+
// Ignore matchs inside comments
55+
foreach ($commentBlocks as $block) {
56+
if ($matchPos > $block[0]) {
57+
if ($matchPos < $block[1]) {
58+
return $matches[0][0];
59+
}
60+
break;
61+
}
62+
}
63+
3964
try {
4065
$resolvedSourcePath = Path::join(\dirname($asset->sourcePath), $matches[1]);
4166
} catch (RuntimeException $e) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.