Sfoglia il codice sorgente

support @charset in stylesheets retrieved with @import

Gildas 5 anni fa
parent
commit
85299174c4
1 ha cambiato i file con 20 aggiunte e 9 eliminazioni
  1. 20 9
      lib/single-file/single-file-core.js

+ 20 - 9
lib/single-file/single-file-core.js

@@ -943,7 +943,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 				stylesheets.set(element, stylesheetInfo);
 				let stylesheetContent = await getStylesheetContent(element, baseURI, options, workStyleElement);
 				if (!matchCharsetEquals(stylesheetContent, options.charset)) {
-					options.charset = getCharset(stylesheetContent);
+					options = Object.assign({}, options, { charset: getCharset(stylesheetContent) });
 					stylesheetContent = await getStylesheetContent(element, baseURI, options, workStyleElement);
 				}
 				let stylesheet;
@@ -1569,13 +1569,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 							// ignored
 						}
 						if (testValidURL(resourceURL) && !importedStyleSheets.has(resourceURL)) {
-							const content = await util.getContent(resourceURL, {
-								maxResourceSize: options.maxResourceSize,
-								maxResourceSizeEnabled: options.maxResourceSizeEnabled,
-								validateTextContentType: true,
-								frameId: options.frameId,
-								resourceReferrer: options.resourceReferrer
-							});
+							const content = await getStylesheetContent(resourceURL);
 							resourceURL = content.resourceURL;
 							content.data = getUpdatedResourceContent(resourceURL, content, options);
 							let importedStylesheetContent = removeCssComments(content.data);
@@ -1603,6 +1597,23 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 				}
 			}));
 			return stylesheetContent;
+
+			async function getStylesheetContent(resourceURL) {
+				const content = await util.getContent(resourceURL, {
+					maxResourceSize: options.maxResourceSize,
+					maxResourceSizeEnabled: options.maxResourceSizeEnabled,
+					validateTextContentType: true,
+					frameId: options.frameId,
+					charset: options.charset,
+					resourceReferrer: options.resourceReferrer
+				});
+				if (!matchCharsetEquals(content.data, content.charset || options.charset)) {
+					options = Object.assign({}, options, { charset: getCharset(stylesheetContent) });
+					return getStylesheetContent(resourceURL);
+				} else {
+					return content;
+				}
+			}
 		}
 
 		static resolveStylesheetURLs(stylesheetContent, baseURI, workStylesheet) {
@@ -1653,7 +1664,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 					validateTextContentType: true
 				});
 				if (!matchCharsetEquals(content.data, content.charset || options.charset)) {
-					options.charset = getCharset(content.data);
+					options = Object.assign({}, options, { charset: getCharset(stylesheetContent) });
 					return ProcessorHelper.resolveLinkStylesheetURLs(resourceURL, baseURI, options, workStylesheet);
 				}
 				resourceURL = content.resourceURL;