Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 93e8814

Browse files
bug #58046 [AssetMapper] Fix JsDeliver import regexp (smnandre)
This PR was merged into the 6.4 branch. Discussion ---------- [AssetMapper] Fix JsDeliver import regexp | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #57969 | License | MIT Following import were not handled in the JSDeliverEsmResolver, due to the `$` character. ```js import jQuery$1 from "/npm/[email protected]/+esm"; ``` This PR updates the regex to handle this case. Commits ------- 45f3835 [AssetMapper] Fix JsDeliver import regexp
2 parents f502013 + 45f3835 commit 93e8814

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Symfony/Component/AssetMapper/ImportMap/Resolver/JsDelivrEsmResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class JsDelivrEsmResolver implements PackageResolverInterface
2828
public const URL_PATTERN_DIST = self::URL_PATTERN_DIST_CSS.'/+esm';
2929
public const URL_PATTERN_ENTRYPOINT = 'https://data.jsdelivr.com/v1/packages/npm/%s@%s/entrypoints';
3030

31-
public const IMPORT_REGEX = '#(?:import\s*(?:\w+,)?(?:(?:\{[^}]*\}|\w+|\*\s*as\s+\w+)\s*\bfrom\s*)?|export\s*(?:\{[^}]*\}|\*)\s*from\s*)("/npm/((?:@[^/]+/)?[^@]+?)(?:@([^/]+))?((?:/[^/]+)*?)/\+esm")#';
31+
public const IMPORT_REGEX = '#(?:import\s*(?:[\w$]+,)?(?:(?:\{[^}]*\}|[\w$]+|\*\s*as\s+[\w$]+)\s*\bfrom\s*)?|export\s*(?:\{[^}]*\}|\*)\s*from\s*)("/npm/((?:@[^/]+/)?[^@]+?)(?:@([^/]+))?((?:/[^/]+)*?)/\+esm")#';
3232

3333
private const ES_MODULE_SHIMS = 'es-module-shims';
3434

src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,13 @@ public static function provideImportRegex(): iterable
686686
['datatables.net-select', '1.7.0'],
687687
],
688688
];
689+
690+
yield 'import with name containing a dollar sign' => [
691+
'import jQuery$1 from "/npm/[email protected]/+esm";',
692+
[
693+
['jquery', '3.7.0'],
694+
],
695+
];
689696
}
690697

691698
private static function createRemoteEntry(string $importName, string $version, ImportMapType $type = ImportMapType::JS, ?string $packageSpecifier = null): ImportMapEntry

0 commit comments

Comments
 (0)