瀏覽代碼

remove invalid fonts embedded in data URIs

Gildas 7 年之前
父節點
當前提交
97f3148cf9
共有 1 個文件被更改,包括 14 次插入5 次删除
  1. 14 5
      lib/single-file/single-file-core.js

+ 14 - 5
lib/single-file/single-file-core.js

@@ -1316,16 +1316,25 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 											content = EMPTY_DATA_URI;
 										}
 									}
-									declaration.value.children.forEach(token => {
-										if (token.type == "Url" && DocUtil.removeQuotes(Util.getCSSValue(token.value)) == originalResourceURL) {
-											token.value.value = content;
-										}
-									});
+									replaceURLs(declaration, originalResourceURL, content);
+								}
+							} else if (resourceURL.startsWith(DATA_URI_PREFIX) && !resourceURL.startsWith(PREFIX_DATA_URI_VND) && !resourceURL.startsWith(PREFIX_DATA_URI_IMAGE_SVG)) {
+								const validResource = await DocUtil.validFont(resourceURL);
+								if (!validResource) {
+									replaceURLs(declaration, originalResourceURL, EMPTY_DATA_URI);
 								}
 							}
 						}));
 					}
 				}));
+
+				function replaceURLs(declaration, oldURL, newURL) {
+					declaration.value.children.forEach(token => {
+						if (token.type == "Url" && DocUtil.removeQuotes(Util.getCSSValue(token.value)) == oldURL) {
+							token.value.value = newURL;
+						}
+					});
+				}
 			}
 		}