Skip to content

Commit b36d3e0

Browse files
Merge branch '6.4' into 7.0
* 6.4: [AssetMapper] Fixing js sourceMappingURL extraction when sourceMappingURL used in code [VarExporter] Deprecate per-property lazy-initializers [Routing] Extend old Annotations from new Attributes [Mailer] Update default Mailjet port Bump Symfony version to 6.4.0 Update VERSION for 6.4.0-BETA3 Update CHANGELOG for 6.4.0-BETA3
2 parents 8a38db9 + 1811555 commit b36d3e0

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

ImportMap/Resolver/JsDelivrEsmResolver.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,10 @@ private function makeImportsBare(string $content, array &$dependencies): string
248248
}, $content);
249249

250250
// source maps are not also downloaded - so remove the sourceMappingURL
251-
$content = preg_replace('{//# sourceMappingURL=.*$}m', '', $content);
251+
// remove the final one only (in case sourceMappingURL is used in the code)
252+
if (false !== $lastPos = strrpos($content, '//# sourceMappingURL=')) {
253+
$content = substr($content, 0, $lastPos).preg_replace('{//# sourceMappingURL=.*$}m', '', substr($content, $lastPos));
254+
}
252255

253256
return preg_replace('{/\*# sourceMappingURL=[^ ]*+ \*/}', '', $content);
254257
}

Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,30 @@ public static function provideDownloadPackagesTests()
430430
],
431431
];
432432

433-
yield 'css file removes importmap' => [
433+
yield 'js sourcemap is correctly removed when sourceMapping appears in the JS' => [
434+
[
435+
'es-module-shims' => self::createRemoteEntry('es-module-shims', version: '1.8.2'),
436+
],
437+
[
438+
[
439+
'url' => '/[email protected]/+esm',
440+
'body' => <<<'EOF'
441+
const je="\n//# sourceURL=",Ue="\n//# sourceMappingURL=",Me=/^(text|application)\/(x-)?javascript(;|$)/,_e=/^(application)\/wasm(;|$)/,Ie=/^(text|application)\/json(;|$)/,Re=/^(text|application)\/css(;|$)/,Te=/url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g;export{t as default};
442+
//# sourceMappingURL=/sm/ef3916de598f421a779ba0e69af94655b2043095cde2410cc01893452d893338.map
443+
EOF
444+
],
445+
],
446+
[
447+
'es-module-shims' => [
448+
'content' => <<<'EOF'
449+
const je="\n//# sourceURL=",Ue="\n//# sourceMappingURL=",Me=/^(text|application)\/(x-)?javascript(;|$)/,_e=/^(application)\/wasm(;|$)/,Ie=/^(text|application)\/json(;|$)/,Re=/^(text|application)\/css(;|$)/,Te=/url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g;export{t as default};
450+
EOF,
451+
'dependencies' => [],
452+
],
453+
],
454+
];
455+
456+
yield 'css file removes sourcemap' => [
434457
['lodash' => self::createRemoteEntry('bootstrap/dist/bootstrap.css', version: '5.0.6', type: ImportMapType::CSS)],
435458
[
436459
[

0 commit comments

Comments
 (0)