From 77d449a074e2ba8cbe209226d8169a85fd1d9e8b Mon Sep 17 00:00:00 2001 From: Simone Stasi Date: Thu, 6 Feb 2025 13:44:56 +0100 Subject: [PATCH 1/3] [html] fix TypeError in nth-child query selector --- pkgs/html/lib/src/query_selector.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/html/lib/src/query_selector.dart b/pkgs/html/lib/src/query_selector.dart index b57b81145a..0c1857ba3f 100644 --- a/pkgs/html/lib/src/query_selector.dart +++ b/pkgs/html/lib/src/query_selector.dart @@ -220,7 +220,7 @@ class SelectorEvaluator extends Visitor { final literal = exprs[0] as LiteralTerm; final parent = _element!.parentNode; return parent != null && - (literal.value as num) > 0 && + (literal.value is num && literal.value as num > 0) && parent.nodes.indexOf(_element) == literal.value; } break; From 609c10987d0866e3e4bcb734ede610b7d314d5d3 Mon Sep 17 00:00:00 2001 From: Simone Stasi Date: Thu, 17 Apr 2025 18:56:55 +0200 Subject: [PATCH 2/3] [html] explicitly reject nth-child with non numeric values --- pkgs/html/lib/src/query_selector.dart | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkgs/html/lib/src/query_selector.dart b/pkgs/html/lib/src/query_selector.dart index 0c1857ba3f..0c48db24ee 100644 --- a/pkgs/html/lib/src/query_selector.dart +++ b/pkgs/html/lib/src/query_selector.dart @@ -218,10 +218,17 @@ class SelectorEvaluator extends Visitor { final exprs = node.expression.expressions; if (exprs.length == 1 && exprs[0] is LiteralTerm) { final literal = exprs[0] as LiteralTerm; + + if (literal.value is! num) { + // non numeric values (e.g. `nth-child(even)`) are not supported + return false; + } + + final numericLiteral = literal.value as num; final parent = _element!.parentNode; return parent != null && - (literal.value is num && literal.value as num > 0) && - parent.nodes.indexOf(_element) == literal.value; + numericLiteral > 0 && + parent.nodes.indexOf(_element) == numericLiteral; } break; From f2398684b653cd5892a4b0f5f451c38bff86894d Mon Sep 17 00:00:00 2001 From: Simone Stasi Date: Thu, 17 Apr 2025 19:01:23 +0200 Subject: [PATCH 3/3] [html] bump version --- pkgs/html/CHANGELOG.md | 4 ++++ pkgs/html/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/html/CHANGELOG.md b/pkgs/html/CHANGELOG.md index 9a881e9d78..079d8e5b3d 100644 --- a/pkgs/html/CHANGELOG.md +++ b/pkgs/html/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.15.6-wip + +- Fixed a TypeError in nth-child with non numeric value (e.g. `nth-child(even)`) + ## 0.15.5 - Require Dart `3.2`. diff --git a/pkgs/html/pubspec.yaml b/pkgs/html/pubspec.yaml index 447b98e186..cdc502f0a7 100644 --- a/pkgs/html/pubspec.yaml +++ b/pkgs/html/pubspec.yaml @@ -1,5 +1,5 @@ name: html -version: 0.15.5 +version: 0.15.6-wip description: APIs for parsing and manipulating HTML content outside the browser. repository: https://github.com/dart-lang/tools/tree/main/pkgs/html issue_tracker: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Ahtml