Socket
Socket
Sign inDemoInstall

css-what

Package Overview
Dependencies
0
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.0.0 to 5.0.1

127

lib/parse.js

@@ -11,14 +11,10 @@ "use strict";

var reEscape = /\\([\da-f]{1,6}\s?|(\s)|.)/gi;
// Modified version of https://github.com/jquery/sizzle/blob/master/src/sizzle.js#L87
var reAttr = /^\s*(?:(\*|[-\w]*)\|)?((?:\\.|[\w\u00b0-\uFFFF-])+)\s*(?:(\S?)=\s*(?:(['"])((?:[^\\]|\\[^])*?)\4|(#?(?:\\.|[\w\u00b0-\uFFFF-])*)|)|)\s*([iIsS])?\s*\]/;
var actionTypes = {
undefined: "exists",
"": "equals",
"~": "element",
"^": "start",
$: "end",
"*": "any",
"!": "not",
"|": "hyphen",
};
var actionTypes = new Map([
["~", "element"],
["^", "start"],
["$", "end"],
["*", "any"],
["!", "not"],
["|", "hyphen"],
]);
var Traversals = {

@@ -201,4 +197,3 @@ ">": "child",

}
else if (firstChar === "/" &&
selector.charAt(selectorIndex + 1) === "*") {
else if (selector.startsWith("/*", selectorIndex)) {
var endIndex = selector.indexOf("*/", selectorIndex + 2);

@@ -229,28 +224,94 @@ if (endIndex < 0) {

else if (firstChar === "[") {
var attributeMatch = selector
.slice(selectorIndex + 1)
.match(reAttr);
if (!attributeMatch) {
throw new Error("Malformed attribute selector: " + selector.slice(selectorIndex));
stripWhitespace(1);
// Determine attribute name and namespace
var name_2 = void 0;
var namespace = null;
if (selector.charAt(selectorIndex) === "|") {
namespace = "";
selectorIndex += 1;
}
var completeSelector = attributeMatch[0], _d = attributeMatch[1], namespace = _d === void 0 ? null : _d, baseName = attributeMatch[2], actionType = attributeMatch[3], _e = attributeMatch[5], quotedValue = _e === void 0 ? "" : _e, _f = attributeMatch[6], value = _f === void 0 ? quotedValue : _f, forceIgnore = attributeMatch[7];
selectorIndex += completeSelector.length + 1;
var name_2 = unescapeCSS(baseName);
if (selector.startsWith("*|", selectorIndex)) {
namespace = "*";
selectorIndex += 2;
}
name_2 = getName(0);
if (namespace === null &&
selector.charAt(selectorIndex) === "|" &&
selector.charAt(selectorIndex + 1) !== "=") {
namespace = name_2;
name_2 = getName(1);
}
if ((_a = options.lowerCaseAttributeNames) !== null && _a !== void 0 ? _a : !options.xmlMode) {
name_2 = name_2.toLowerCase();
}
var ignoreCase =
// If the forceIgnore flag is set (either `i` or `s`), use that value
forceIgnore
? forceIgnore.toLowerCase() === "i"
: // If `xmlMode` is set, there are no rules; return `null`.
options.xmlMode
? null
: // Otherwise, use the `caseInsensitiveAttributes` list.
caseInsensitiveAttributes.has(name_2);
stripWhitespace(0);
// Determine comparison operation
var action = "exists";
var possibleAction = actionTypes.get(selector.charAt(selectorIndex));
if (possibleAction) {
action = possibleAction;
if (selector.charAt(selectorIndex + 1) !== "=") {
throw new Error("Expected `=`");
}
stripWhitespace(2);
}
else if (selector.charAt(selectorIndex) === "=") {
action = "equals";
stripWhitespace(1);
}
// Determine value
var value = "";
var ignoreCase = null;
if (action !== "exists") {
if (quotes.has(selector.charAt(selectorIndex))) {
var quote = selector.charAt(selectorIndex);
var sectionEnd = selectorIndex + 1;
while (sectionEnd < selector.length &&
(selector.charAt(sectionEnd) !== quote ||
isEscaped(sectionEnd))) {
sectionEnd += 1;
}
if (selector.charAt(sectionEnd) !== quote) {
throw new Error("Attribute value didn't end");
}
value = unescapeCSS(selector.slice(selectorIndex + 1, sectionEnd));
selectorIndex = sectionEnd + 1;
}
else {
var valueStart = selectorIndex;
while (selectorIndex < selector.length &&
((!isWhitespace(selector.charAt(selectorIndex)) &&
selector.charAt(selectorIndex) !== "]") ||
isEscaped(selectorIndex))) {
selectorIndex += 1;
}
value = unescapeCSS(selector.slice(valueStart, selectorIndex));
}
stripWhitespace(0);
// See if we have a force ignore flag
var forceIgnore = selector.charAt(selectorIndex);
// If the forceIgnore flag is set (either `i` or `s`), use that value
if (forceIgnore === "s" || forceIgnore === "S") {
ignoreCase = false;
stripWhitespace(1);
}
else if (forceIgnore === "i" || forceIgnore === "I") {
ignoreCase = true;
stripWhitespace(1);
}
}
// If `xmlMode` is set, there are no rules; otherwise, use the `caseInsensitiveAttributes` list.
if (!options.xmlMode) {
// TODO: Skip this for `exists`, as there is no value to compare to.
ignoreCase !== null && ignoreCase !== void 0 ? ignoreCase : (ignoreCase = caseInsensitiveAttributes.has(name_2));
}
if (selector.charAt(selectorIndex) !== "]") {
throw new Error("Attribute selector didn't terminate");
}
selectorIndex += 1;
var attributeSelector = {
type: "attribute",
name: name_2,
action: actionTypes[actionType],
value: unescapeCSS(value),
action: action,
value: value,
namespace: namespace,

@@ -257,0 +318,0 @@ ignoreCase: ignoreCase,

@@ -27,2 +27,3 @@ "use strict";

")",
"'",
]));

@@ -29,0 +30,0 @@ /**

@@ -5,3 +5,3 @@ {

"description": "a CSS selector parser",
"version": "5.0.0",
"version": "5.0.1",
"funding": {

@@ -33,3 +33,3 @@ "url": "https://github.com/sponsors/fb55"

"@types/jest": "^26.0.3",
"@types/node": "^14.0.5",
"@types/node": "^15.0.1",
"@typescript-eslint/eslint-plugin": "^4.1.0",

@@ -41,5 +41,5 @@ "@typescript-eslint/parser": "^4.1.0",

"eslint-plugin-node": "^11.1.0",
"jest": "^26.0.1",
"jest": "^27.0.1",
"prettier": "^2.0.5",
"ts-jest": "^26.0.0",
"ts-jest": "^27.0.1",
"typescript": "^4.0.2"

@@ -53,4 +53,3 @@ },

"jest": {
"preset": "ts-jest",
"testEnvironment": "node"
"preset": "ts-jest"
},

@@ -57,0 +56,0 @@ "prettier": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc