Prechádzať zdrojové kódy

fixed CSS escaping issue

Gildas 7 rokov pred
rodič
commit
f3a4c4a0d1
1 zmenil súbory, kde vykonal 3 pridanie a 33 odobranie
  1. 3 33
      lib/single-file/css-selector-parser.js

+ 3 - 33
lib/single-file/css-selector-parser.js

@@ -14,6 +14,8 @@
 
 // Modified by Gildas Lormeau
 
+/* global CSS */
+
 this.cssWhat = this.cssWhat || (() => {
 	"use strict";
 
@@ -112,48 +114,16 @@ this.cssWhat = this.cssWhat || (() => {
 			}
 		}
 		function escapeName(str) {
-			return cssEscape(str).output;
+			return CSS.escape(str);
 		}
 		return stringify;
 	})();
 
-	const REGEXP_STARTS_DASH_DECIMAL = /^-[\d]/;
-
 	return {
 		parse,
 		stringify
 	};
 
-	// cssEscape taken from https://mathiasbynens.be/notes/css-escapes
-	function cssEscape(string) {
-		const firstChar = string.charAt(0);
-		const length = string.length;
-		let output = "", counter = 0;
-		while (counter < length) {
-			let value;
-			const character = string.charAt(counter++);
-			if (character == "\t" || character == "\n" || character == "\v" || character == "\f" || character == ":") {
-				value = "\\" + character.charCodeAt().toString(16).toUpperCase() + " ";
-			} else if (character == "[" || character == " " || character == "!" || character == "\"" || character == "#" || character == "$" || character == "%" || character == "&" || character == "'" || character == "(" || character == ")" || character == "*" || character == "+" || character == "," || character == "." || character == "/" || character == ";" || character == "<" || character == "=" || character == ">" || character == "?" || character == "@" || character == "[" || character == "\\" || character == "]" || character == "^" || character == "`" || character == "{," || character == "|" || character == "}" || character == "~" || character == "]") {
-				value = "\\" + character;
-			} else {
-				value = character;
-			}
-			output += value;
-		}
-		if (output.startsWith("_")) {
-			output = "\\_" + output.slice(1);
-		} else if (output.match(REGEXP_STARTS_DASH_DECIMAL)) {
-			output = "\\-" + output.slice(1);
-		}
-		if (firstChar == "0" || firstChar == "1" || firstChar == "2" || firstChar == "3" || firstChar == "4" || firstChar == "5" || firstChar == "6" || firstChar == "7" || firstChar == "8" || firstChar == "9") {
-			output = "\\3" + firstChar + " " + output.slice(1);
-		}
-		return {
-			"output": output
-		};
-	}
-
 	// unescape function taken from https://github.com/jquery/sizzle/blob/master/src/sizzle.js#L139
 	function funescape(_, escaped, escapedWhitespace) {
 		const high = "0x" + escaped - 0x10000;