Jelajahi Sumber

remove charset quotes

Gildas 7 tahun lalu
induk
melakukan
ad098ac9c0
1 mengubah file dengan 14 tambahan dan 1 penghapusan
  1. 14 1
      lib/single-file/single-file-browser.js

+ 14 - 1
lib/single-file/single-file-browser.js

@@ -90,7 +90,7 @@ this.SingleFile = this.SingleFile || (() => {
 				if (charSetValue) {
 					const matchCharSet = charSetValue.match(/^charset=(.*)/);
 					if (matchCharSet) {
-						charSet = matchCharSet[1];
+						charSet = removeQuotes(matchCharSet[1]);
 					}
 				}
 			}
@@ -137,6 +137,19 @@ this.SingleFile = this.SingleFile || (() => {
 		}
 	}
 
+	const REGEXP_SIMPLE_QUOTES_STRING = /^'(.*?)'$/;
+	const REGEXP_DOUBLE_QUOTES_STRING = /^"(.*?)"$/;
+
+	function removeQuotes(string) {
+		string = string.toLowerCase().trim();
+		if (string.match(REGEXP_SIMPLE_QUOTES_STRING)) {
+			string = string.replace(REGEXP_SIMPLE_QUOTES_STRING, "$1");
+		} else {
+			string = string.replace(REGEXP_DOUBLE_QUOTES_STRING, "$1");
+		}
+		return string.trim();
+	}
+
 	// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
 	function hex(buffer) {
 		var hexCodes = [];