|
@@ -79,11 +79,20 @@ this.SingleFile = this.SingleFile || (() => {
|
|
|
resourceContent = options && options.asDataURI ? "data:base64," : "";
|
|
resourceContent = options && options.asDataURI ? "data:base64," : "";
|
|
|
}
|
|
}
|
|
|
let contentType = resourceContent.headers && resourceContent.headers.get("content-type");
|
|
let contentType = resourceContent.headers && resourceContent.headers.get("content-type");
|
|
|
|
|
+ let charSet;
|
|
|
if (contentType) {
|
|
if (contentType) {
|
|
|
- contentType = contentType.match(/^([^;]*)/)[0].toLowerCase();
|
|
|
|
|
|
|
+ const matchContentType = contentType.toLowerCase().split(";");
|
|
|
|
|
+ contentType = matchContentType[0].trim();
|
|
|
if (contentType.indexOf("/") <= 0) {
|
|
if (contentType.indexOf("/") <= 0) {
|
|
|
contentType = null;
|
|
contentType = null;
|
|
|
}
|
|
}
|
|
|
|
|
+ const charSetValue = matchContentType[1] && matchContentType[1].trim();
|
|
|
|
|
+ if (charSetValue) {
|
|
|
|
|
+ const matchCharSet = charSetValue.match(/^charset=(.*)/);
|
|
|
|
|
+ if (matchCharSet) {
|
|
|
|
|
+ charSet = matchCharSet[1];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
if (options && options.asDataURI) {
|
|
if (options && options.asDataURI) {
|
|
|
try {
|
|
try {
|
|
@@ -101,10 +110,11 @@ this.SingleFile = this.SingleFile || (() => {
|
|
|
return "data:base64,";
|
|
return "data:base64,";
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- const matchCharset = contentType && contentType.match(/\s*;\s*charset\s*=\s*"?([^";]*)"?(;|$)/i);
|
|
|
|
|
- let charSet;
|
|
|
|
|
- if (matchCharset && matchCharset[1] || options.charSet) {
|
|
|
|
|
- charSet = (matchCharset && matchCharset[1].toLowerCase()) || options.charSet;
|
|
|
|
|
|
|
+ if (!charSet) {
|
|
|
|
|
+ const matchCharset = contentType && contentType.match(/\s*;\s*charset\s*=\s*"?([^";]*)"?(;|$)/i);
|
|
|
|
|
+ if (matchCharset && matchCharset[1] || options.charSet) {
|
|
|
|
|
+ charSet = (matchCharset && matchCharset[1].toLowerCase()) || options.charSet;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
if (!charSet) {
|
|
if (!charSet) {
|
|
|
charSet = "utf-8";
|
|
charSet = "utf-8";
|