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 2e6618b

Browse filesBrowse files
weaverryannicolas-grekas
authored andcommitted
[AssetMapper] Fixing jsdelivr regex to catch 2x export syntax in a row
1 parent 93afb42 commit 2e6618b
Copy full SHA for 2e6618b

File tree

2 files changed

+42
-14
lines changed
Filter options

2 files changed

+42
-14
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/AssetMapper/ImportMap/Resolver/JsDelivrEsmResolver.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php
+41-13Lines 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.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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.