Просмотр исходного кода

added fallback implementation (fixes #414)

Former-commit-id: db8e26dce273bd4621aaa04539bd5ea603c08b6e
Gildas 5 лет назад
Родитель
Сommit
4eba9f15ff
1 измененных файлов с 13 добавлено и 1 удалено
  1. 13 1
      lib/single-file/single-file-core.js

+ 13 - 1
lib/single-file/single-file-core.js

@@ -2034,7 +2034,19 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 	}
 
 	function removeCssComments(stylesheetContent) {
-		return stylesheetContent.replace(/\/\*(.|\s)*?\*\//g, "");
+		try {
+			return stylesheetContent.replace(/\/\*(.|\s)*?\*\//g, "");
+		} catch (error) {
+			let start, end;
+			do {
+				start = stylesheetContent.indexOf("/*");
+				end = stylesheetContent.indexOf("*/", start + 2);
+				if (start != -1 && end != -1) {
+					stylesheetContent = stylesheetContent.substring(0, start) + stylesheetContent.substr(end + 2);
+				}
+			} while (start != -1 && end != -1);
+			return stylesheetContent;
+		}
 	}
 
 	function wrapMediaQuery(stylesheetContent, mediaQuery) {