diff --git a/src/Symfony/Component/AssetMapper/ImportMap/Resolver/JsDelivrEsmResolver.php b/src/Symfony/Component/AssetMapper/ImportMap/Resolver/JsDelivrEsmResolver.php index dae1a3d1a8656..bbc9199cc7c08 100644 --- a/src/Symfony/Component/AssetMapper/ImportMap/Resolver/JsDelivrEsmResolver.php +++ b/src/Symfony/Component/AssetMapper/ImportMap/Resolver/JsDelivrEsmResolver.php @@ -248,7 +248,10 @@ private function makeImportsBare(string $content, array &$dependencies): string }, $content); // source maps are not also downloaded - so remove the sourceMappingURL - $content = preg_replace('{//# sourceMappingURL=.*$}m', '', $content); + // remove the final one only (in case sourceMappingURL is used in the code) + if (false !== $lastPos = strrpos($content, '//# sourceMappingURL=')) { + $content = substr($content, 0, $lastPos).preg_replace('{//# sourceMappingURL=.*$}m', '', substr($content, $lastPos)); + } return preg_replace('{/\*# sourceMappingURL=[^ ]*+ \*/}', '', $content); } diff --git a/src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php b/src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php index 1c2ac78d0d2f4..121e80a3a0b3a 100644 --- a/src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php +++ b/src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php @@ -430,7 +430,30 @@ public static function provideDownloadPackagesTests() ], ]; - yield 'css file removes importmap' => [ + yield 'js sourcemap is correctly removed when sourceMapping appears in the JS' => [ + [ + 'es-module-shims' => self::createRemoteEntry('es-module-shims', version: '1.8.2'), + ], + [ + [ + 'url' => '/es-module-shims@1.8.2/+esm', + 'body' => <<<'EOF' +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}; +//# sourceMappingURL=/sm/ef3916de598f421a779ba0e69af94655b2043095cde2410cc01893452d893338.map +EOF + ], + ], + [ + 'es-module-shims' => [ + 'content' => <<<'EOF' +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}; +EOF, + 'dependencies' => [], + ], + ], + ]; + + yield 'css file removes sourcemap' => [ ['lodash' => self::createRemoteEntry('bootstrap/dist/bootstrap.css', version: '5.0.6', type: ImportMapType::CSS)], [ [ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy