Skip to content

Navigation Menu

Sign in
Appearance settings

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 5f78910

Browse filesBrowse files
committed
bug #54113 [AssetMapper] Throw exception in Javascript compiler when PCRE error (smnandre)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [AssetMapper] Throw exception in Javascript compiler when PCRE error | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #... | License | MIT `preg_match_callback` can return null when a PCRE error occured, leading there to a TypeError. Let's throw an exception and expose the error message. (follows #54078 / complementary to #54079 ) Commits ------- 2333b58 [AssetMapper] Throw exception in Javascript compiler when PCRE error
2 parents a184a18 + 2333b58 commit 5f78910
Copy full SHA for 5f78910

File tree

Expand file treeCollapse file tree

2 files changed

+20
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/AssetMapper/Compiler/JavaScriptImportPathCompiler.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/AssetMapper/Tests/Compiler/JavaScriptImportPathCompilerTest.php
+19Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.