Skip to content

Commit

Permalink
fix unclosed attribute selector
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane committed Aug 12, 2024
1 parent ccda793 commit 5d69d0c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Fixed parsing unclosed attribute selector (such as `a[href`).

## v2.11.3

- Fixed for TypeScript 5.5.
Expand Down
2 changes: 2 additions & 0 deletions parser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ type PreprocessUnchecked<I> = I extends `${infer L}\\${Quotes}${infer R}` // rem
? PreprocessUnchecked<`${L}${R}`>
: I extends `${infer L}[${string}]${infer R}` // process attribute
? PreprocessUnchecked<`${L}#x${R}`> // replace it with a fake ID selector
: I extends `${infer L}[${string}${infer R}` // process unclosed attribute
? PreprocessUnchecked<`${L}#x${R}`> // replace it with a fake ID selector
: I

/** Parse `:is()` and `:where()` */
Expand Down
1 change: 1 addition & 0 deletions parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type _Tests = [
Expect<Equal<ParseSelector<'div[data-key*=value]'>, HTMLDivElement>>,
Expect<Equal<ParseSelector<'div[data-key="value"i]'>, HTMLDivElement>>,
Expect<Equal<ParseSelector<'div[data-key="value"s]'>, HTMLDivElement>>,
Expect<Equal<ParseSelector<'div[data-key'>, HTMLDivElement>>,
Expect<Equal<ParseSelector<'div[]'>, Element>>,
Expect<
Equal<ParseSelector<'link[type="application/atom+xml"]'>, HTMLLinkElement>
Expand Down

0 comments on commit 5d69d0c

Please sign in to comment.