ソースを参照

detect repeated urls in a property value

Former-commit-id: ad45ad908154d78add7b8daad261d8a893fb1294
Gildas 6 年 前
コミット
7e4bb97dc1
1 ファイル変更9 行追加4 行削除
  1. 9 4
      lib/single-file/single-file-core.js

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

@@ -1486,7 +1486,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 		}
 
 		static resolveStylesheetURLs(stylesheetContent, baseURI) {
-			const urlFunctions = Util.getUrlFunctions(stylesheetContent);
+			const urlFunctions = Util.getUrlFunctions(stylesheetContent, true);
 			urlFunctions.map(urlFunction => {
 				const originalResourceURL = Util.matchURL(urlFunction);
 				const resourceURL = Util.normalizeURL(originalResourceURL);
@@ -1560,7 +1560,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 			async function processFontFaceRule(ruleData) {
 				await Promise.all(ruleData.block.children.toArray().map(async declaration => {
 					if (declaration.type == "Declaration" && declaration.value.children) {
-						const urlFunctions = Util.getUrlFunctions(Util.getCSSValue(declaration.value));
+						const urlFunctions = Util.getUrlFunctions(Util.getCSSValue(declaration.value), true);
 						await Promise.all(urlFunctions.map(async urlFunction => {
 							const originalResourceURL = Util.matchURL(urlFunction);
 							const resourceURL = Util.normalizeURL(originalResourceURL);
@@ -1859,8 +1859,13 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 			return new RegExp(string.replace(REGEXP_ESCAPE, "\\$1"), "gi");
 		}
 
-		static getUrlFunctions(stylesheetContent) {
-			return Array.from(new Set(stylesheetContent.match(REGEXP_URL_FN) || []));
+		static getUrlFunctions(stylesheetContent, unique) {
+			const result = stylesheetContent.match(REGEXP_URL_FN) || [];
+			if (unique) {
+				return [...new Set(result)];
+			} else {
+				return result;
+			}
 		}
 
 		static getImportFunctions(stylesheetContent) {