Fix the relative path problem of CSS url() in CSSStyleSheet() (#2326)

This commit is contained in:
Liu Fei 2021-05-02 20:16:23 +08:00 committed by GitHub
parent f34cdc6382
commit dcf7456642
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,5 @@
import { resolveUrl } from '../common.js';
/*
* Loads JSON, CSS, Wasm module types based on file extension
* filters and content type verifications
@ -33,6 +35,9 @@
if (cssContentType.test(contentType))
return res.text()
.then(function (source) {
source = source.replace(/url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g, function (match, quotes, relUrl1, relUrl2) {
return 'url(' + quotes + resolveUrl(relUrl1 || relUrl2, url) + quotes + ')';
});
return new Response(new Blob([
'System.register([],function(e){return{execute:function(){var s=new CSSStyleSheet();s.replaceSync(' + JSON.stringify(source) + ');e("default",s)}}})'
], {