From 21fe29b637ddaada739d3d6cd55694a7b95d2343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Rabasse?= Date: Fri, 25 Oct 2024 01:56:48 +0200 Subject: [PATCH] [AssetMapper] Fix `JavaScriptImportPathCompiler` regex for non-latin characters --- Compiler/JavaScriptImportPathCompiler.php | 2 +- .../JavaScriptImportPathCompilerTest.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Compiler/JavaScriptImportPathCompiler.php b/Compiler/JavaScriptImportPathCompiler.php index 9a0546a..3fab0e6 100644 --- a/Compiler/JavaScriptImportPathCompiler.php +++ b/Compiler/JavaScriptImportPathCompiler.php @@ -50,7 +50,7 @@ final class JavaScriptImportPathCompiler implements AssetCompilerInterface ) \s*[\'"`](\.\/[^\'"`\n]++|(\.\.\/)*+[^\'"`\n]++)[\'"`]\s*[;\)] ? - /mx'; + /mxu'; public function __construct( private readonly ImportMapConfigReader $importMapConfigReader, diff --git a/Tests/Compiler/JavaScriptImportPathCompilerTest.php b/Tests/Compiler/JavaScriptImportPathCompilerTest.php index ba47fc4..a73c2a4 100644 --- a/Tests/Compiler/JavaScriptImportPathCompilerTest.php +++ b/Tests/Compiler/JavaScriptImportPathCompilerTest.php @@ -172,6 +172,22 @@ public static function provideCompileTests(): iterable 'expectedJavaScriptImports' => ['/assets/other.js' => ['lazy' => false, 'asset' => 'other.js', 'add' => true]], ]; + yield 'static_named_import_with_unicode_character' => [ + 'input' => 'import { ɵmyFunction } from "./other.js";', + 'expectedJavaScriptImports' => ['/assets/other.js' => ['lazy' => false, 'asset' => 'other.js', 'add' => true]], + ]; + + yield 'static_multiple_named_imports' => [ + 'input' => << ['/assets/other.js' => ['lazy' => false, 'asset' => 'other.js', 'add' => true]], + ]; + yield 'static_import_everything' => [ 'input' => 'import * as myModule from "./other.js";', 'expectedJavaScriptImports' => ['/assets/other.js' => ['lazy' => false, 'asset' => 'other.js', 'add' => true]],