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 91ed84e

Browse filesBrowse files
committed
[AssetMapper] Throw exception in Javascript compiler when PCRE error
preg_match_callback can return `null` when a PCRE error occured, leading there to a TypeError. Let's throw an exception and expose the preg_error message.
1 parent 182e93e commit 91ed84e
Copy full SHA for 91ed84e

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+17
-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
@@ -116,7 +116,7 @@ public function compile(string $content, MappedAsset $asset, AssetMapperInterfac
116116
$relativeImportPath = $this->makeRelativeForJavaScript($relativeImportPath);
117117

118118
return str_replace($importedModule, $relativeImportPath, $fullImportString);
119-
}, $content, -1, $count, \PREG_OFFSET_CAPTURE);
119+
}, $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()));
120120
}
121121

122122
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
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,4 +641,20 @@ 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', 20);
657+
$compiler->compile($content, $javascriptAsset, $assetMapper);
658+
ini_set('pcre.backtrack_limit', $limit);
659+
}
644660
}

0 commit comments

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