|
|
@@ -962,13 +962,15 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
const match = DomUtil.matchImport(cssImport);
|
|
|
if (match) {
|
|
|
const resourceURL = DomUtil.normalizeURL(match.resourceURL);
|
|
|
- if (resourceURL != baseURI && resourceURL != ABOUT_BLANK_URI) {
|
|
|
+ if (!DomUtil.testIgnoredPath(resourceURL) && DomUtil.testValidPath(resourceURL)) {
|
|
|
const styleSheetUrl = new URL(match.resourceURL, baseURI).href;
|
|
|
- let importedStylesheetContent = await Download.getContent(styleSheetUrl, { asDataURI: false, maxResourceSize: options.maxResourceSize, maxResourceSizeEnabled: options.maxResourceSizeEnabled });
|
|
|
- importedStylesheetContent = DomUtil.wrapMediaQuery(importedStylesheetContent, match.media);
|
|
|
- if (stylesheetContent.includes(cssImport)) {
|
|
|
- importedStylesheetContent = await DomProcessorHelper.resolveImportURLs(importedStylesheetContent, styleSheetUrl, options);
|
|
|
- stylesheetContent = stylesheetContent.replace(DomUtil.getRegExp(cssImport), importedStylesheetContent);
|
|
|
+ if (DomUtil.testValidURL(resourceURL)) {
|
|
|
+ let importedStylesheetContent = await Download.getContent(styleSheetUrl, { asDataURI: false, maxResourceSize: options.maxResourceSize, maxResourceSizeEnabled: options.maxResourceSizeEnabled });
|
|
|
+ importedStylesheetContent = DomUtil.wrapMediaQuery(importedStylesheetContent, match.media);
|
|
|
+ if (stylesheetContent.includes(cssImport)) {
|
|
|
+ importedStylesheetContent = await DomProcessorHelper.resolveImportURLs(importedStylesheetContent, styleSheetUrl, options);
|
|
|
+ stylesheetContent = stylesheetContent.replace(DomUtil.getRegExp(cssImport), importedStylesheetContent);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -984,7 +986,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
if (!DomUtil.testIgnoredPath(resourceURL)) {
|
|
|
if (DomUtil.testValidPath(resourceURL, baseURI)) {
|
|
|
const resolvedURL = new URL(resourceURL, baseURI).href;
|
|
|
- if (resourceURL != resolvedURL && stylesheetContent.includes(urlFunction)) {
|
|
|
+ if (DomUtil.testValidURL(resolvedURL, baseURI) && resourceURL != resolvedURL && stylesheetContent.includes(urlFunction)) {
|
|
|
stylesheetContent = stylesheetContent.replace(DomUtil.getRegExp(urlFunction), urlFunction.replace(originalResourceURL, resolvedURL));
|
|
|
}
|
|
|
}
|
|
|
@@ -1077,22 +1079,25 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
resourceURL = DomUtil.normalizeURL(resourceURL);
|
|
|
if (!DomUtil.testIgnoredPath(resourceURL)) {
|
|
|
resourceElement.setAttribute(attributeName, EMPTY_IMAGE);
|
|
|
- if (DomUtil.testValidURL(resourceURL, baseURI)) {
|
|
|
- try {
|
|
|
- const { content, indexResource, duplicate } = await batchRequest.addURL(new URL(resourceURL, baseURI).href);
|
|
|
- if (removeElementIfMissing && content == EMPTY_DATA_URI) {
|
|
|
- resourceElement.remove();
|
|
|
- } else {
|
|
|
- if (content.startsWith(prefixDataURI) || content.startsWith(PREFIX_DATA_URI_NO_MIMETYPE) || content.startsWith(PREFIX_DATA_URI_OCTET_STREAM)) {
|
|
|
- if (processDuplicates && duplicate && options.groupDuplicateImages && DomUtil.replaceImageSource(resourceElement, SINGLE_FILE_VARIABLE_NAME_PREFIX + indexResource, options)) {
|
|
|
- DomUtil.insertVariable(doc, indexResource, content, options);
|
|
|
- } else {
|
|
|
- resourceElement.setAttribute(attributeName, content);
|
|
|
+ if (DomUtil.testValidPath(resourceURL, baseURI)) {
|
|
|
+ resourceURL = new URL(resourceURL, baseURI).href;
|
|
|
+ if (DomUtil.testValidURL(resourceURL, baseURI)) {
|
|
|
+ try {
|
|
|
+ const { content, indexResource, duplicate } = await batchRequest.addURL(resourceURL);
|
|
|
+ if (removeElementIfMissing && content == EMPTY_DATA_URI) {
|
|
|
+ resourceElement.remove();
|
|
|
+ } else {
|
|
|
+ if (content.startsWith(prefixDataURI) || content.startsWith(PREFIX_DATA_URI_NO_MIMETYPE) || content.startsWith(PREFIX_DATA_URI_OCTET_STREAM)) {
|
|
|
+ if (processDuplicates && duplicate && options.groupDuplicateImages && DomUtil.replaceImageSource(resourceElement, SINGLE_FILE_VARIABLE_NAME_PREFIX + indexResource, options)) {
|
|
|
+ DomUtil.insertVariable(doc, indexResource, content, options);
|
|
|
+ } else {
|
|
|
+ resourceElement.setAttribute(attributeName, content);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ } catch (error) {
|
|
|
+ /* ignored */
|
|
|
}
|
|
|
- } catch (error) {
|
|
|
- /* ignored */
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1103,12 +1108,13 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
const attributeName = "xlink:href";
|
|
|
await Promise.all(Array.from(resourceElements).map(async resourceElement => {
|
|
|
const originalResourceURL = resourceElement.getAttribute(attributeName);
|
|
|
- const resourceURL = DomUtil.normalizeURL(originalResourceURL);
|
|
|
- if (!DomUtil.testIgnoredPath(resourceURL)) {
|
|
|
+ let resourceURL = DomUtil.normalizeURL(originalResourceURL);
|
|
|
+ if (DomUtil.testValidPath(resourceURL) && !DomUtil.testIgnoredPath(resourceURL)) {
|
|
|
resourceElement.setAttribute(attributeName, EMPTY_IMAGE);
|
|
|
+ resourceURL = new URL(resourceURL, baseURI).href;
|
|
|
if (DomUtil.testValidURL(resourceURL, baseURI)) {
|
|
|
try {
|
|
|
- const { content } = await batchRequest.addURL(new URL(resourceURL, baseURI).href, false);
|
|
|
+ const { content } = await batchRequest.addURL(resourceURL, false);
|
|
|
const DOMParser = DOM.getParser();
|
|
|
if (DOMParser) {
|
|
|
const svgDoc = new DOMParser().parseFromString(content, "image/svg+xml");
|
|
|
@@ -1137,16 +1143,21 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
await Promise.all(Array.from(resourceElements).map(async resourceElement => {
|
|
|
const srcset = DOM.parseSrcset(resourceElement.getAttribute(attributeName));
|
|
|
const srcsetValues = await Promise.all(srcset.map(async srcsetValue => {
|
|
|
- const resourceURL = DomUtil.normalizeURL(srcsetValue.url);
|
|
|
+ let resourceURL = DomUtil.normalizeURL(srcsetValue.url);
|
|
|
if (!DomUtil.testIgnoredPath(resourceURL)) {
|
|
|
- if (DomUtil.testValidURL(resourceURL, baseURI)) {
|
|
|
- try {
|
|
|
- const { content } = await batchRequest.addURL(new URL(resourceURL, baseURI).href);
|
|
|
- if (!content.startsWith(prefixDataURI) && !content.startsWith(PREFIX_DATA_URI_NO_MIMETYPE) && !content.startsWith(PREFIX_DATA_URI_OCTET_STREAM)) {
|
|
|
+ if (DomUtil.testValidPath(resourceURL)) {
|
|
|
+ resourceURL = new URL(resourceURL, baseURI).href;
|
|
|
+ if (DomUtil.testValidURL(resourceURL, baseURI)) {
|
|
|
+ try {
|
|
|
+ const { content } = await batchRequest.addURL(resourceURL);
|
|
|
+ if (!content.startsWith(prefixDataURI) && !content.startsWith(PREFIX_DATA_URI_NO_MIMETYPE) && !content.startsWith(PREFIX_DATA_URI_OCTET_STREAM)) {
|
|
|
+ resourceElement.setAttribute(attributeName, EMPTY_IMAGE);
|
|
|
+ }
|
|
|
+ return content + (srcsetValue.w ? " " + srcsetValue.w + "w" : srcsetValue.d ? " " + srcsetValue.d + "x" : "");
|
|
|
+ } catch (error) {
|
|
|
resourceElement.setAttribute(attributeName, EMPTY_IMAGE);
|
|
|
}
|
|
|
- return content + (srcsetValue.w ? " " + srcsetValue.w + "w" : srcsetValue.d ? " " + srcsetValue.d + "x" : "");
|
|
|
- } catch (error) {
|
|
|
+ } else {
|
|
|
resourceElement.setAttribute(attributeName, EMPTY_IMAGE);
|
|
|
}
|
|
|
} else {
|