8000 Merge branch '6.4' into 7.0 · symfony/symfony@3c39c04 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c39c04

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: [AssetMapper] Throw exception in Javascript compiler when PCRE error
2 parents 24cf1eb + 5f78910 commit 3c39c04

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Symfony/Component/AssetMapper/Compiler/JavaScriptImportPathCompiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function compile(string $content, MappedAsset $asset, AssetMapperInterfac
115115
$relativeImportPath = $this->makeRelativeForJavaScript($relativeImportPath);
116116

117117
return str_replace($importedModule, $relativeImportPath, $fullImportString);
118-
}, $content, -1, $count, \PREG_OFFSET_CAPTURE);
118+
}, $content, -1, $count, \PREG_OFFSET_CAPTURE) ?? throw new RuntimeException(sprintf('Failed to compile JavaScript import paths in "%s". Error: "%s".', $asset->sourcePath, preg_last_error_msg()));
119119
}
120120

121121
public function supports(MappedAsset $asset): bool

src/Symfony/Component/AssetMapper/Tests/Compiler/JavaScriptImportPathCompilerTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,4 +641,23 @@ public function testErrorMessageAvoidsCircularException()
641641
// should not be caught.
642642
$this->assertSame($content, $compiled);
643643
}
644+
645+
public function testCompilerThrowsExceptionOnPcreError()
646+
{
647+
$compiler = new JavaScriptImportPathCompiler($this->createMock(ImportMapConfigReader::class));
648+
$content = str_repeat('foo "import * ', 50);
649+
$javascriptAsset = new MappedAsset('app.js', '/project/assets/app.js', publicPathWithoutDigest: '/assets/app.js');
650+
$assetMapper = $this->createMock(AssetMapperInterface::class);
651+
652+
$this->expectException(RuntimeException::class);
653+
$this->expectExceptionMessage('Failed to compile JavaScript import paths in "/project/assets/app.js". Error: "Backtrack limit exhausted".');
654+
655+
$limit = \ini_get('pcre.backtrack_limit');
656+
ini_set('pcre.backtrack_limit', 10);
657+
try {
658+
$compiler->compile($content, $javascriptAsset, $assetMapper);
659+
} finally {
660+
ini_set('pcre.backtrack_limit', $limit);
661+
}
662+
}
644663
}

0 commit comments

Comments
 (0)
0