From 4469f7ad8a437275a3cf3433abaa93eb15ee2ccc Mon Sep 17 00:00:00 2001 From: Istvan Soos Date: Fri, 22 Dec 2023 11:09:47 +0100 Subject: [PATCH] Use role attribute only on interactive or allowlisted components. --- app/lib/frontend/templates/detail_page.dart | 9 ++++-- .../templates/views/shared/detail/tabs.dart | 1 - .../frontend/golden/my_activity_log_page.html | 14 ++++----- .../frontend/golden/my_liked_packages.html | 14 ++++----- app/test/frontend/golden/my_packages.html | 14 ++++----- app/test/frontend/golden/my_publishers.html | 14 ++++----- .../golden/pkg_activity_log_page.html | 30 +++++++++---------- app/test/frontend/golden/pkg_admin_page.html | 30 +++++++++---------- .../frontend/golden/pkg_changelog_page.html | 22 +++++++------- .../frontend/golden/pkg_example_page.html | 22 +++++++------- .../frontend/golden/pkg_install_page.html | 22 +++++++------- app/test/frontend/golden/pkg_score_page.html | 22 +++++++------- app/test/frontend/golden/pkg_show_page.html | 30 +++++++++---------- .../golden/pkg_show_page_discontinued.html | 22 +++++++------- .../golden/pkg_show_page_flutter_plugin.html | 30 +++++++++---------- .../golden/pkg_show_page_publisher.html | 22 +++++++------- .../golden/pkg_show_page_retracted.html | 22 +++++++------- ..._page_retracted_non_retracted_version.html | 22 +++++++------- .../golden/pkg_show_version_page.html | 22 +++++++------- .../frontend/golden/pkg_versions_page.html | 22 +++++++------- .../golden/publisher_activity_log_page.html | 10 +++---- .../frontend/golden/publisher_admin_page.html | 10 +++---- .../golden/publisher_packages_page.html | 14 ++++----- .../publisher_unlisted_packages_page.html | 14 ++++----- .../testdata/goldens/packages/oxygen.html | 22 +++++++------- .../goldens/packages/oxygen/changelog.html | 22 +++++++------- .../goldens/packages/oxygen/example.html | 22 +++++++------- .../goldens/packages/oxygen/install.html | 22 +++++++------- .../goldens/packages/oxygen/license.html | 26 ++++++++-------- .../goldens/packages/oxygen/score.html | 22 +++++++------- .../goldens/packages/oxygen/versions.html | 22 +++++++------- .../packages/oxygen/versions/1.0.0.html | 22 +++++++------- .../oxygen/versions/1.0.0/changelog.html | 22 +++++++------- .../oxygen/versions/1.0.0/example.html | 22 +++++++------- .../oxygen/versions/1.0.0/install.html | 22 +++++++------- .../oxygen/versions/1.0.0/license.html | 26 ++++++++-------- .../packages/oxygen/versions/1.0.0/score.html | 22 +++++++------- .../packages/oxygen/versions/2.0.0.html | 22 +++++++------- .../lib/validation/html/html_validation.dart | 15 ++++++++++ 39 files changed, 402 insertions(+), 383 deletions(-) diff --git a/app/lib/frontend/templates/detail_page.dart b/app/lib/frontend/templates/detail_page.dart index d00e3f922b..69108a7dac 100644 --- a/app/lib/frontend/templates/detail_page.dart +++ b/app/lib/frontend/templates/detail_page.dart @@ -95,8 +95,13 @@ class Tab { if (isPrivate) '-private', ]; - d.Node get titleNode => - href == null ? d.text(title) : d.a(href: href, text: title); + d.Node get titleNode => href == null + ? d.text(title) + : d.a( + href: href, + text: title, + attributes: {'role': 'button'}, + ); bool get hasContent => contentNode != null; diff --git a/app/lib/frontend/templates/views/shared/detail/tabs.dart b/app/lib/frontend/templates/views/shared/detail/tabs.dart index c834c58bfb..bbba670f07 100644 --- a/app/lib/frontend/templates/views/shared/detail/tabs.dart +++ b/app/lib/frontend/templates/views/shared/detail/tabs.dart @@ -19,7 +19,6 @@ d.Node detailTabsNode({ children: tabs.map( (t) => d.li( classes: t.titleClasses, - attributes: {'role': 'button'}, child: t.titleNode, ), ), diff --git a/app/test/frontend/golden/my_activity_log_page.html b/app/test/frontend/golden/my_activity_log_page.html index 4788e06918..11c770894e 100644 --- a/app/test/frontend/golden/my_activity_log_page.html +++ b/app/test/frontend/golden/my_activity_log_page.html @@ -157,16 +157,16 @@

admin

diff --git a/app/test/frontend/golden/my_liked_packages.html b/app/test/frontend/golden/my_liked_packages.html index f6a9a96452..1e5d8c86d1 100644 --- a/app/test/frontend/golden/my_liked_packages.html +++ b/app/test/frontend/golden/my_liked_packages.html @@ -158,15 +158,15 @@

user

diff --git a/app/test/frontend/golden/my_packages.html b/app/test/frontend/golden/my_packages.html index 9428bcd2c9..994c38e35b 100644 --- a/app/test/frontend/golden/my_packages.html +++ b/app/test/frontend/golden/my_packages.html @@ -157,15 +157,15 @@

user

diff --git a/app/test/frontend/golden/my_publishers.html b/app/test/frontend/golden/my_publishers.html index e29a4b7538..3d9ca895bc 100644 --- a/app/test/frontend/golden/my_publishers.html +++ b/app/test/frontend/golden/my_publishers.html @@ -157,15 +157,15 @@

user

diff --git a/app/test/frontend/golden/pkg_activity_log_page.html b/app/test/frontend/golden/pkg_activity_log_page.html index 77346ff79c..0061236292 100644 --- a/app/test/frontend/golden/pkg_activity_log_page.html +++ b/app/test/frontend/golden/pkg_activity_log_page.html @@ -212,28 +212,28 @@

Metadata

diff --git a/app/test/frontend/golden/pkg_admin_page.html b/app/test/frontend/golden/pkg_admin_page.html index b5a58b02b8..334793f06c 100644 --- a/app/test/frontend/golden/pkg_admin_page.html +++ b/app/test/frontend/golden/pkg_admin_page.html @@ -212,27 +212,27 @@

Metadata

diff --git a/app/test/frontend/golden/pkg_changelog_page.html b/app/test/frontend/golden/pkg_changelog_page.html index e0576308b5..37be59e47e 100644 --- a/app/test/frontend/golden/pkg_changelog_page.html +++ b/app/test/frontend/golden/pkg_changelog_page.html @@ -186,21 +186,21 @@

Metadata

diff --git a/app/test/frontend/golden/pkg_example_page.html b/app/test/frontend/golden/pkg_example_page.html index 3967e98ba1..518bc4ddbd 100644 --- a/app/test/frontend/golden/pkg_example_page.html +++ b/app/test/frontend/golden/pkg_example_page.html @@ -186,21 +186,21 @@

Metadata

diff --git a/app/test/frontend/golden/pkg_install_page.html b/app/test/frontend/golden/pkg_install_page.html index 32c98a1a30..5c0d0a537a 100644 --- a/app/test/frontend/golden/pkg_install_page.html +++ b/app/test/frontend/golden/pkg_install_page.html @@ -186,21 +186,21 @@

Metadata

diff --git a/app/test/frontend/golden/pkg_score_page.html b/app/test/frontend/golden/pkg_score_page.html index f3c849cd6f..07f692ccc6 100644 --- a/app/test/frontend/golden/pkg_score_page.html +++ b/app/test/frontend/golden/pkg_score_page.html @@ -186,22 +186,22 @@

Metadata

diff --git a/app/test/frontend/golden/pkg_show_page.html b/app/test/frontend/golden/pkg_show_page.html index 34764a87c1..aee1da00d1 100644 --- a/app/test/frontend/golden/pkg_show_page.html +++ b/app/test/frontend/golden/pkg_show_page.html @@ -186,27 +186,27 @@

Metadata

diff --git a/app/test/frontend/golden/pkg_show_page_discontinued.html b/app/test/frontend/golden/pkg_show_page_discontinued.html index b0fe200761..a36d9545e1 100644 --- a/app/test/frontend/golden/pkg_show_page_discontinued.html +++ b/app/test/frontend/golden/pkg_show_page_discontinued.html @@ -172,21 +172,21 @@

Metadata

diff --git a/app/test/frontend/golden/pkg_show_page_flutter_plugin.html b/app/test/frontend/golden/pkg_show_page_flutter_plugin.html index eee5010a90..fbc325aacc 100644 --- a/app/test/frontend/golden/pkg_show_page_flutter_plugin.html +++ b/app/test/frontend/golden/pkg_show_page_flutter_plugin.html @@ -175,27 +175,27 @@

Metadata

diff --git a/app/test/frontend/golden/pkg_show_page_publisher.html b/app/test/frontend/golden/pkg_show_page_publisher.html index c8be5f0e98..db9242da7b 100644 --- a/app/test/frontend/golden/pkg_show_page_publisher.html +++ b/app/test/frontend/golden/pkg_show_page_publisher.html @@ -180,21 +180,21 @@

Metadata

diff --git a/app/test/frontend/golden/pkg_show_page_retracted.html b/app/test/frontend/golden/pkg_show_page_retracted.html index 96467f9691..e82d6c7896 100644 --- a/app/test/frontend/golden/pkg_show_page_retracted.html +++ b/app/test/frontend/golden/pkg_show_page_retracted.html @@ -168,21 +168,21 @@

Metadata

diff --git a/app/test/frontend/golden/pkg_show_page_retracted_non_retracted_version.html b/app/test/frontend/golden/pkg_show_page_retracted_non_retracted_version.html index 033dc49aff..4355890087 100644 --- a/app/test/frontend/golden/pkg_show_page_retracted_non_retracted_version.html +++ b/app/test/frontend/golden/pkg_show_page_retracted_non_retracted_version.html @@ -176,21 +176,21 @@

Metadata

diff --git a/app/test/frontend/golden/pkg_show_version_page.html b/app/test/frontend/golden/pkg_show_version_page.html index ba166cf086..6b5fcdc51e 100644 --- a/app/test/frontend/golden/pkg_show_version_page.html +++ b/app/test/frontend/golden/pkg_show_version_page.html @@ -186,21 +186,21 @@

Metadata

diff --git a/app/test/frontend/golden/pkg_versions_page.html b/app/test/frontend/golden/pkg_versions_page.html index 89431d6a93..40440d7960 100644 --- a/app/test/frontend/golden/pkg_versions_page.html +++ b/app/test/frontend/golden/pkg_versions_page.html @@ -186,21 +186,21 @@

Metadata

diff --git a/app/test/frontend/golden/publisher_activity_log_page.html b/app/test/frontend/golden/publisher_activity_log_page.html index 252d20fe32..a9b398239f 100644 --- a/app/test/frontend/golden/publisher_activity_log_page.html +++ b/app/test/frontend/golden/publisher_activity_log_page.html @@ -141,13 +141,13 @@

example.com

diff --git a/app/test/frontend/golden/publisher_admin_page.html b/app/test/frontend/golden/publisher_admin_page.html index 8387d9c234..630cb72088 100644 --- a/app/test/frontend/golden/publisher_admin_page.html +++ b/app/test/frontend/golden/publisher_admin_page.html @@ -141,12 +141,12 @@

example.com

diff --git a/app/test/frontend/golden/publisher_packages_page.html b/app/test/frontend/golden/publisher_packages_page.html index c1f70012ef..6ca63cd043 100644 --- a/app/test/frontend/golden/publisher_packages_page.html +++ b/app/test/frontend/golden/publisher_packages_page.html @@ -141,15 +141,15 @@

example.com

diff --git a/app/test/frontend/golden/publisher_unlisted_packages_page.html b/app/test/frontend/golden/publisher_unlisted_packages_page.html index 368d255e1a..9152582f1d 100644 --- a/app/test/frontend/golden/publisher_unlisted_packages_page.html +++ b/app/test/frontend/golden/publisher_unlisted_packages_page.html @@ -141,15 +141,15 @@

example.com

diff --git a/app/test/task/testdata/goldens/packages/oxygen.html b/app/test/task/testdata/goldens/packages/oxygen.html index 3cd81bd30d..fc7c5fcb73 100644 --- a/app/test/task/testdata/goldens/packages/oxygen.html +++ b/app/test/task/testdata/goldens/packages/oxygen.html @@ -178,21 +178,21 @@

Metadata

diff --git a/app/test/task/testdata/goldens/packages/oxygen/changelog.html b/app/test/task/testdata/goldens/packages/oxygen/changelog.html index fcd819dc01..cee53c3087 100644 --- a/app/test/task/testdata/goldens/packages/oxygen/changelog.html +++ b/app/test/task/testdata/goldens/packages/oxygen/changelog.html @@ -178,21 +178,21 @@

Metadata

diff --git a/app/test/task/testdata/goldens/packages/oxygen/example.html b/app/test/task/testdata/goldens/packages/oxygen/example.html index 43024ed7f3..163b18cc20 100644 --- a/app/test/task/testdata/goldens/packages/oxygen/example.html +++ b/app/test/task/testdata/goldens/packages/oxygen/example.html @@ -178,21 +178,21 @@

Metadata

diff --git a/app/test/task/testdata/goldens/packages/oxygen/install.html b/app/test/task/testdata/goldens/packages/oxygen/install.html index 34da5c1e93..eb798136a0 100644 --- a/app/test/task/testdata/goldens/packages/oxygen/install.html +++ b/app/test/task/testdata/goldens/packages/oxygen/install.html @@ -178,21 +178,21 @@

Metadata

diff --git a/app/test/task/testdata/goldens/packages/oxygen/license.html b/app/test/task/testdata/goldens/packages/oxygen/license.html index ff39f9d8f4..9d21cdf0a9 100644 --- a/app/test/task/testdata/goldens/packages/oxygen/license.html +++ b/app/test/task/testdata/goldens/packages/oxygen/license.html @@ -178,24 +178,24 @@

Metadata

diff --git a/app/test/task/testdata/goldens/packages/oxygen/score.html b/app/test/task/testdata/goldens/packages/oxygen/score.html index c820992ca0..73085d8e35 100644 --- a/app/test/task/testdata/goldens/packages/oxygen/score.html +++ b/app/test/task/testdata/goldens/packages/oxygen/score.html @@ -178,22 +178,22 @@

Metadata

diff --git a/app/test/task/testdata/goldens/packages/oxygen/versions.html b/app/test/task/testdata/goldens/packages/oxygen/versions.html index 6c49c97340..032b02db2b 100644 --- a/app/test/task/testdata/goldens/packages/oxygen/versions.html +++ b/app/test/task/testdata/goldens/packages/oxygen/versions.html @@ -178,21 +178,21 @@

Metadata

diff --git a/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0.html b/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0.html index 610182d1e9..77737a7ec3 100644 --- a/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0.html +++ b/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0.html @@ -182,21 +182,21 @@

Metadata

diff --git a/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/changelog.html b/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/changelog.html index e4e31ed552..5b4d14e4aa 100644 --- a/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/changelog.html +++ b/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/changelog.html @@ -182,21 +182,21 @@

Metadata

diff --git a/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/example.html b/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/example.html index 1a7dcea44c..35f73f71cb 100644 --- a/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/example.html +++ b/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/example.html @@ -182,21 +182,21 @@

Metadata

diff --git a/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/install.html b/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/install.html index 51138a4e21..5effffab10 100644 --- a/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/install.html +++ b/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/install.html @@ -182,21 +182,21 @@

Metadata

diff --git a/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/license.html b/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/license.html index e48f3c5903..982eb47ca9 100644 --- a/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/license.html +++ b/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/license.html @@ -182,24 +182,24 @@

Metadata

diff --git a/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/score.html b/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/score.html index d5cade2b6a..bd6a304314 100644 --- a/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/score.html +++ b/app/test/task/testdata/goldens/packages/oxygen/versions/1.0.0/score.html @@ -182,22 +182,22 @@

Metadata

diff --git a/app/test/task/testdata/goldens/packages/oxygen/versions/2.0.0.html b/app/test/task/testdata/goldens/packages/oxygen/versions/2.0.0.html index 3cd81bd30d..fc7c5fcb73 100644 --- a/app/test/task/testdata/goldens/packages/oxygen/versions/2.0.0.html +++ b/app/test/task/testdata/goldens/packages/oxygen/versions/2.0.0.html @@ -178,21 +178,21 @@

Metadata

diff --git a/pkg/_pub_shared/lib/validation/html/html_validation.dart b/pkg/_pub_shared/lib/validation/html/html_validation.dart index beb428acd5..ead929e389 100644 --- a/pkg/_pub_shared/lib/validation/html/html_validation.dart +++ b/pkg/_pub_shared/lib/validation/html/html_validation.dart @@ -144,6 +144,21 @@ void validateHtml(Node root) { 'button tag text content or aria-label must not be empty, found: ${elem.outerHtml}'); } } + + // "role"="" attributes should be on interactive components + final allowedForRole = {'a'}; + for (final elem in querySelectorAll('[role]')) { + final tag = elem.localName!; + final role = elem.attributes['role']; + // image elements may have presentation role + if (tag == 'img' && role == 'presentation') continue; + // interactive elements + if (allowedForRole.contains(tag)) continue; + // material components + if (tag == 'th' && role == 'columnheader') continue; + throw AssertionError( + '<$tag> tag should not have role attribute, found: ${elem.outerHtml}'); + } } /// "Google Search result usually points to the canonical page, unless one of