Skip to content

Commit 2735cf4

Browse files
committed
bug #54014 [AssetMapper] Fix enquoted string pattern (smnandre)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [AssetMapper] Fix enquoted string pattern | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #54012 | License | MIT Alternative to #54012 (fixes the bug and avoid a revert that will reintroduce other previous bugs / missmatches) + add a test to check things work as expected with the standard `app.js` file cc `@weaverryan` `@nicolas`-grekas Commits ------- df618bd [AssetMapper] Fix enquoted string pattern
2 parents fce2d88 + df618bd commit 2735cf4

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ final class JavaScriptImportPathCompiler implements AssetCompilerInterface
3535
(?:\/\/.*) # Lines that start with comments
3636
|
3737
(?:
38-
\'(?:[^\'\\\\]|\\\\.)*\' # Strings enclosed in single quotes
38+
\'(?:[^\'\\\\\n]|\\\\.)*\' # Strings enclosed in single quotes
3939
|
40-
"(?:[^"\\\\]|\\\\.)*" # Strings enclosed in double quotes
40+
"(?:[^"\\\\\n]|\\\\.)*" # Strings enclosed in double quotes
4141
)
4242
|
4343
(?: # Import statements (script captured)
@@ -49,7 +49,7 @@ final class JavaScriptImportPathCompiler implements AssetCompilerInterface
4949
|
5050
\bimport\(
5151
)
52-
\s*[\'"`](\.\/[^\'"`]+|(\.\.\/)*[^\'"`]+)[\'"`]\s*[;\)]
52+
\s*[\'"`](\.\/[^\'"`\n]+|(\.\.\/)*[^\'"`\n]+)[\'"`]\s*[;\)]
5353
?
5454
/mx';
5555

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ public function testCompileFindsCorrectImports(string $input, array $expectedJav
6868
->willReturnCallback(function ($path) {
6969
return match ($path) {
7070
'/project/assets/foo.js' => new MappedAsset('foo.js', '/can/be/anything.js', publicPathWithoutDigest: '/assets/foo.js'),
71+
'/project/assets/bootstrap.js' => new MappedAsset('bootstrap.js', '/can/be/anything.js', publicPathWithoutDigest: '/assets/bootstrap.js'),
7172
'/project/assets/other.js' => new MappedAsset('other.js', '/can/be/anything.js', publicPathWithoutDigest: '/assets/other.js'),
7273
'/project/assets/subdir/foo.js' => new MappedAsset('subdir/foo.js', '/can/be/anything.js', publicPathWithoutDigest: '/assets/subdir/foo.js'),
74+
'/project/assets/styles/app.css' => new MappedAsset('styles/app.css', '/can/be/anything.js', publicPathWithoutDigest: '/assets/styles/app.css'),
75+
'/project/assets/styles/app.scss' => new MappedAsset('styles/app.scss', '/can/be/anything.js', publicPathWithoutDigest: '/assets/styles/app.scss'),
7376
'/project/assets/styles.css' => new MappedAsset('styles.css', '/can/be/anything.js', publicPathWithoutDigest: '/assets/styles.css'),
7477
'/project/assets/vendor/module_in_importmap_remote.js' => new MappedAsset('module_in_importmap_remote.js', '/can/be/anything.js', publicPathWithoutDigest: '/assets/module_in_importmap_remote.js'),
7578
'/project/assets/vendor/@popperjs/core.js' => new MappedAsset('assets/vendor/@popperjs/core.js', '/can/be/anything.js', publicPathWithoutDigest: '/assets/@popperjs/core.js'),
@@ -90,6 +93,26 @@ public function testCompileFindsCorrectImports(string $input, array $expectedJav
9093

9194
public static function provideCompileTests(): iterable
9295
{
96+
yield 'standard_symfony_app_js' => [
97+
'input' => <<<EOF
98+
import './bootstrap.js';
99+
100+
/*
101+
* Welcome to your app's main JavaScript file!
102+
*
103+
* This file will be included onto the page via the importmap() Twig function,
104+
* which should already be in your base.html.twig.
105+
*/
106+
import './styles/app.css';
107+
108+
console.log('This log comes from assets/app.js - welcome to AssetMapper! 🎉');
109+
EOF,
110+
'expectedJavaScriptImports' => [
111+
'/assets/bootstrap.js' => ['lazy' => false, 'asset' => 'bootstrap.js', 'add' => true],
112+
'/assets/styles/app.css' => ['lazy' => false, 'asset' => 'styles/app.css', 'add' => true],
113+
],
114+
];
115+
93116
yield 'dynamic_simple_double_quotes' => [
94117
'input' => 'import("./other.js");',
95118
'expectedJavaScriptImports' => ['/assets/other.js' => ['lazy' => true, 'asset' => 'other.js', 'add' => true]],

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy