From ff21060445d11e604320b9a80c077073313ef898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20B=C3=B6hm?= Date: Thu, 1 Oct 2020 11:31:13 -0700 Subject: [PATCH 1/3] docs: Update funding information --- .github/FUNDING.yml | 14 ++------------ package.json | 1 + 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 5bac4c45..58c38d50 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,12 +1,2 @@ -# These are supported funding model platforms - -github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] -patreon: # Replace with a single Patreon username -open_collective: # Replace with a single Open Collective username -ko_fi: # Replace with a single Ko-fi username -tidelift: "npm/css-what" -community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry -liberapay: # Replace with a single Liberapay username -issuehunt: # Replace with a single IssueHunt username -otechie: # Replace with a single Otechie username -custom: # Replace with a single custom sponsorship URL +github: [fb55] +tidelift: npm/css-what diff --git a/package.json b/package.json index 7b6be953..663936a7 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "name": "css-what", "description": "a CSS selector parser", "version": "3.4.0", + "funding": "https://github.com/sponsors/fb55", "repository": { "url": "https://github.com/fb55/css-what" }, From a05da960e0cbf468eaa84bf6c189119c9afee551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20B=C3=B6hm?= Date: Thu, 1 Oct 2020 12:42:05 -0700 Subject: [PATCH 2/3] fix(parser): Support escaped characters in attribute value --- src/__fixtures__/tests.ts | 215 ++++++++++++++++++++++++++++++++++++++ src/parse.ts | 2 +- src/stringify.ts | 1 + 3 files changed, 217 insertions(+), 1 deletion(-) diff --git a/src/__fixtures__/tests.ts b/src/__fixtures__/tests.ts index 5c9fc313..7ea22f9a 100644 --- a/src/__fixtures__/tests.ts +++ b/src/__fixtures__/tests.ts @@ -483,4 +483,219 @@ export const tests: [string, Selector[][], string][] = [ ], "pseudo selector with data", ], + + /* + * Bad attributes (taken from Sizzle) + * https://github.com/jquery/sizzle/blob/af163873d7cdfc57f18b16c04b1915209533f0b1/test/unit/selector.js#L602-L651 + */ + [ + "[id=types_all]", + [ + [ + { + type: "attribute", + action: "equals", + name: "id", + value: "types_all", + ignoreCase: false, + }, + ], + ], + "Underscores don't need escaping", + ], + [ + "[name=foo\\ bar]", + [ + [ + { + type: "attribute", + action: "equals", + name: "name", + value: "foo bar", + ignoreCase: false, + }, + ], + ], + "Escaped space", + ], + [ + "[name=foo\\.baz]", + [ + [ + { + type: "attribute", + action: "equals", + name: "name", + value: "foo.baz", + ignoreCase: false, + }, + ], + ], + "Escaped dot", + ], + [ + "[name=foo\\[baz\\]]", + [ + [ + { + type: "attribute", + action: "equals", + name: "name", + value: "foo[baz]", + ignoreCase: false, + }, + ], + ], + "Escaped brackets", + ], + [ + "[data-attr='foo_baz\\']']", + [ + [ + { + type: "attribute", + action: "equals", + name: "data-attr", + value: "foo_baz']", + ignoreCase: false, + }, + ], + ], + "Escaped quote + right bracket", + ], + [ + "[data-attr='\\'']", + [ + [ + { + type: "attribute", + action: "equals", + name: "data-attr", + value: "'", + ignoreCase: false, + }, + ], + ], + "Quoted quote", + ], + [ + "[data-attr='\\\\']", + [ + [ + { + type: "attribute", + action: "equals", + name: "data-attr", + value: "\\", + ignoreCase: false, + }, + ], + ], + "Quoted backslash", + ], + [ + "[data-attr='\\\\\\'']", + [ + [ + { + type: "attribute", + action: "equals", + name: "data-attr", + value: "\\'", + ignoreCase: false, + }, + ], + ], + "Quoted backslash quote", + ], + [ + "[data-attr='\\\\\\\\']", + [ + [ + { + type: "attribute", + action: "equals", + name: "data-attr", + value: "\\\\", + ignoreCase: false, + }, + ], + ], + "Quoted backslash backslash", + ], + [ + "[data-attr='\\5C\\\\']", + [ + [ + { + type: "attribute", + action: "equals", + name: "data-attr", + value: "\\\\", + ignoreCase: false, + }, + ], + ], + "Quoted backslash backslash (numeric escape)", + ], + [ + "[data-attr='\\5C \\\\']", + [ + [ + { + type: "attribute", + action: "equals", + name: "data-attr", + value: "\\\\", + ignoreCase: false, + }, + ], + ], + "Quoted backslash backslash (numeric escape with trailing space)", + ], + [ + "[data-attr='\\5C\t\\\\']", + [ + [ + { + type: "attribute", + action: "equals", + name: "data-attr", + value: "\\\\", + ignoreCase: false, + }, + ], + ], + "Quoted backslash backslash (numeric escape with trailing tab)", + ], + [ + "[data-attr='\\04e00']", + [ + [ + { + type: "attribute", + action: "equals", + name: "data-attr", + value: "\u4e00", + ignoreCase: false, + }, + ], + ], + "Long numeric escape (BMP)", + ], + [ + "[data-attr='\\01D306A']", + [ + [ + { + type: "attribute", + action: "equals", + name: "data-attr", + value: "\uD834\uDF06A", + ignoreCase: false, + }, + ], + ], + "Long numeric escape (non-BMP)", + ], ]; diff --git a/src/parse.ts b/src/parse.ts index 009430db..2f9d2849 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -70,7 +70,7 @@ export type TraversalType = const reName = /^[^\\]?(?:\\(?:[\da-f]{1,6}\s?|.)|[\w\-\u00b0-\uFFFF])+/; const reEscape = /\\([\da-f]{1,6}\s?|(\s)|.)/gi; // Modified version of https://github.com/jquery/sizzle/blob/master/src/sizzle.js#L87 -const reAttr = /^\s*((?:\\.|[\w\u00b0-\uFFFF-])+)\s*(?:(\S?)=\s*(?:(['"])([^]*?)\3|(#?(?:\\.|[\w\u00b0-\uFFFF-])*)|)|)\s*(i)?\]/; +const reAttr = /^\s*((?:\\.|[\w\u00b0-\uFFFF-])+)\s*(?:(\S?)=\s*(?:(['"])((?:[^\\]|\\[^])*?)\3|(#?(?:\\.|[\w\u00b0-\uFFFF-])*)|)|)\s*(i)?\]/; const actionTypes: { [key: string]: AttributeAction } = { undefined: "exists", diff --git a/src/stringify.ts b/src/stringify.ts index a4a9d873..68694421 100644 --- a/src/stringify.ts +++ b/src/stringify.ts @@ -16,6 +16,7 @@ const charsToEscape = new Set([ "[", "]", " ", + "\\", ]); export default function stringify(token: Selector[][]): string { From eefc98a05fa29a402c6645e375df47d7f3958dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20B=C3=B6hm?= Date: Thu, 1 Oct 2020 12:43:04 -0700 Subject: [PATCH 3/3] 3.4.1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2a4aac95..320ca222 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "css-what", - "version": "3.4.0", + "version": "3.4.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 663936a7..e683925b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Felix Böhm (http://feedic.com)", "name": "css-what", "description": "a CSS selector parser", - "version": "3.4.0", + "version": "3.4.1", "funding": "https://github.com/sponsors/fb55", "repository": { "url": "https://github.com/fb55/css-what"