8000 bug #51728 [AssetMapper] Fixing jsdelivr regex to catch 2x export syn… · symfony/symfony@810ad9d · GitHub
[go: up one dir, main page]

Skip to content

Commit 810ad9d

Browse files
bug #51728 [AssetMapper] Fixing jsdelivr regex to catch 2x export syntax in a row (weaverryan)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [AssetMapper] Fixing jsdelivr regex to catch 2x export syntax in a row | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | none | License | MIT | Doc PR | Not needed Hi! I found a new variant on the import syntax used by jsdelivr. This updates the regex to cover it and enhances the test suite around this pattern matching. The source of the problem is this content: https://cdn.jsdelivr.net/npm/`@vue`/runtime-dom@3.3.4/+esm Cheers! Commits ------- 2e6618b [AssetMapper] Fixing jsdelivr regex to catch 2x export syntax in a row
2 parents f47f589 + 2e6618b commit 810ad9d

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class JsDelivrEsmResolver implements PackageResolverInterface
2525
public const URL_PATTERN_VERSION = 'https://data.jsdelivr.com/v1/packages/npm/%s/resolved?specifier=%s';
2626
public const URL_PATTERN_DIST = 'https://cdn.jsdelivr.net/npm/%s@%s%s/+esm';
2727

28-
public const IMPORT_REGEX = '{from"/npm/([^@]*@?[\S]+)@([^/]+)/\+esm"}';
28+
public const IMPORT_REGEX = '{from"/npm/([^@]*@?\S+?)@([^/]+)/\+esm"}';
2929

3030
private HttpClientInterface $httpClient;
3131

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

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -235,21 +235,49 @@ public static function provideResolvePackagesTests(): iterable
235235
];
236236
}
237237

238-
public function testImportRegex()
238+
/**
239+
* @dataProvider provideImportRegex
240+
*/
241+
public function testImportRegex(string $subject, array $expectedPackages)
239242
{
240-
$subject = 'import{Color as t}from"/npm/@kurkle/color@0.3.2/+esm";import t from"/npm/jquery@3.7.0/+esm";import e from"/npm/popper.js@1.16.1/+esm";console.log("yo");';
241243
preg_match_all(JsDelivrEsmResolver::IMPORT_REGEX, $subject, $matches);
242244

243-
$this->assertCount(3, $matches[0]);
244-
$this->assertSame([
245-
'@kurkle/color',
246-
'jquery',
247-
'popper.js',
248-
], $matches[1]);
249-
$this->assertSame([
250-
'0.3.2',
251-
'3.7.0',
252-
'1.16.1',
253-
], $matches[2]);
245+
$this->assertCount(\count($expectedPackages), $matches[0]);
246+
$expectedNames = [];
247+
$expectedVersions = [];
248+
foreach ($expectedPackages as $packageData) {
249+
$expectedNames[] = $packageData[0];
250+
$expectedVersions[] = $packageData[1];
251+
}
252+
$this->assertSame($expectedNames, $matches[1]);
253+
$this->assertSame($expectedVersions, $matches[2]);
254+
}
255+
256+
public static function provideImportRegex(): iterable
257+
{
258+
yield 'standard import format' => [
259+
'import{Color as t}from"/npm/@kurkle/color@0.3.2/+esm";import t from"/npm/jquery@3.7.0/+esm";import e from"/npm/popper.js@1.16.1/+esm";console.log("yo");',
260+
[
261+
['@kurkle/color', '0.3.2'],
262+
['jquery', '3.7.0'],
263+
['popper.js', '1.16.1'],
264+
],
265+
];
266+
267+
yield 'export and import format' => [
268+
'export*from"/npm/@vue/runtime-dom@3.3.4/+esm";const e=()=>{};export{e as compile};export default null;',
269+
[
270+
['@vue/runtime-dom', '3.3.4'],
271+
],
272+
];
273+
274+
yield 'multiple export format & import' => [
275+
'import{defineComponent as e,nextTick as t,createVNode as n,getCurrentInstance as r,watchPostEffect as s,onMounted as o,onUnmounted as i,h as a,BaseTransition as l,BaseTransitionPropsValidators as c,Fragment as u,Static as p,useTransitionState as f,onUpdated as d,toRaw as m,getTransitionRawChildren as h,setTransitionHooks as v,resolveTransitionHooks as g,createRenderer as _,createHydrationRenderer as b,camelize as y,callWithAsyncErrorHandling as C}from"/npm/@vue/runtime-core@3.3.4/+esm";export*from"/npm/@vue/runtime-core@3.3 60AF .4/+esm";import{isArray as S,camelize as E,toNumber as A,hyphenate as w,extend as T,EMPTY_OBJ as x,isObject as P,looseToNumber as k,looseIndexOf as L,isSet as N,looseEqual as $,isFunction as R,isString as M,invokeArrayFns as V,isOn as B,isModelListener as D,capitalize as I,isSpecialBooleanAttr as O,includeBooleanAttr as F}from"/npm/@vue/shared@3.3.4/+esm";const U="undefined"!=typeof document?',
276+
[
277+
['@vue/runtime-core', '3.3.4'],
278+
['@vue/runtime-core', '3.3.4'],
279+
['@vue/shared', '3.3.4'],
280+
],
281+
];
254282
}
255283
}

0 commit comments

Comments
 (0)
0