:nth-* selectors incorrectly reject detached elements when the formula matches every index
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 82/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- typescript
調査の方向性
issueでリンクされている compileNth の最適化箇所を src/pseudo-selectors/filters.ts で読み、その高速パスを通常の兄弟要素カウントのパスと比較します。issueにある切り離された要素の再現例を使って、4つの :nth-* のケースを確認します。各セレクターの (1) と (n) が切り離された要素に一致すれば完了です。issueではテストファイルが指定されていないため、カバレッジを追加する前に、関連する既存テストを探します。
索引モデルが issue の本文から書いたものです。
説明
In [email protected], a detached element matches :nth-child(1) but fails :nth-child(n). The same inconsistency affects all four :nth-* pseudo-classes.
This reproduces with the default adapter:
import { is } from 'css-select';
import { Element } from 'domhandler';
const element = new Element('div', {});
for (const pseudo of [
'nth-child',
'nth-last-child',
'nth-of-type',
'nth-last-of-type',
]) {
console.log(
pseudo,
is(element, `:${pseudo}(1)`),
is(element, `:${pseudo}(n)`),
);
}
Actual output:
nth-child true false
nth-last-child true false
nth-of-type true false
nth-last-of-type true false
Expected: true true for every row. A detached element is its only inclusive sibling, at index 1. Selectors Level 4 explicitly allows these pseudo-classes to match elements without parents.
The apparent cause is the compileNth optimization:
if (nthCheck === boolbase.trueFunc && !ofSelector) {
return (element) =>
getElementParent(element, adapter) !== null && next(element);
}
This path requires an element parent, whereas the ordinary sibling-counting path handles detached elements correctly. Returning next directly appears sufficient for this optimization.
- 主要言語
- TypeScript
- スター
- 636
- フォーク
- 85
- 平均マージ
- 1分
- マージ済み PR(30日)
- 13
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
fb55/css-select のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
fb55/css-select#1931 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
:is(), :where(), :not() and aliases inside :has() are read as relative to the :has() element対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
fb55/css-select#1930 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
A descendant combinator after a complex :is() or :not() keeps answers it should not対応中かも @Aschenbath が 12 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
fb55/css-select#1929 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
:has(.a .b) matches with the :has() element itself as .a対応中かも @manav4u が 14 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
fb55/css-select#1928 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
fb55/css-select#1838 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
fb55/css-select の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
vega/vega-webgpu#40 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
openwatersio/slackwater#550 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
bug size:small
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
fb55/htmlparser2#2579 ·
メンテナーはふだん 1 日以内に返信