css-selector-tokenizer
Advanced tools
Comparing version 0.5.1 to 0.5.2
@@ -26,4 +26,8 @@ "use strict"; | ||
function unescapeString(content) { | ||
return content.replace(/\\./g, function(escaped) { | ||
return escaped.substr(1); | ||
return content.replace(/\\([a-fA-F0-9]{4}|.)/g, function(escaped) { | ||
if(escaped.length > 2) { | ||
return String.fromCharCode(parseInt(escaped.substr(1), 16)); | ||
} else { | ||
return escaped.substr(1); | ||
} | ||
}); | ||
@@ -91,2 +95,3 @@ } | ||
this.root = this.stack.pop(); | ||
this.value = this.root.nodes[this.root.nodes.length - 1]; | ||
} | ||
@@ -130,3 +135,3 @@ } | ||
"url\\((\\s*)((?:[^\\\\)'\"]|\\\\.)*)(\\s*)\\)": urlMatch, | ||
"(\\w+)\\((\\s*)": nestedItemMatch, | ||
"([\\w\-]+)\\((\\s*)": nestedItemMatch, | ||
"(\\s*)(\\))": nestedItemEndMatch, | ||
@@ -133,0 +138,0 @@ ",(\\s*)": commaMatch, |
@@ -5,2 +5,23 @@ "use strict"; | ||
function escape(str, stringType) { | ||
return str.replace(/["'\\\x80-\uFFFF]/g, function(match) { | ||
switch(match) { | ||
case "\"": | ||
if(stringType === "\"") { | ||
return "\\\""; | ||
} | ||
return match; | ||
case "'": | ||
if(stringType === "'") { | ||
return "\\'"; | ||
} | ||
return match; | ||
case "\\": | ||
return "\\\\"; | ||
default: | ||
return "\\" + (0x10000 + match.charCodeAt(0)).toString(16).substr(1); | ||
} | ||
}); | ||
} | ||
function stringifyWithoutBeforeAfter(tree) { | ||
@@ -23,5 +44,5 @@ switch(tree.type) { | ||
case "'": | ||
return "'" + tree.value.replace(/'/g, "\\'") + "'"; | ||
return "'" + escape(tree.value, "'") + "'"; | ||
case "\"": | ||
return "\"" + tree.value.replace(/"/g, "\\\"") + "\""; | ||
return "\"" + escape(tree.value, "\"") + "\""; | ||
} | ||
@@ -28,0 +49,0 @@ /* istanbul ignore next */ |
{ | ||
"name": "css-selector-tokenizer", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "Parses and stringifies CSS selectors", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15452
466