diff --git a/scanner/dashboard/index.html b/scanner/dashboard/index.html index 132bc31b..8df0a0ee 100644 --- a/scanner/dashboard/index.html +++ b/scanner/dashboard/index.html @@ -281,7 +281,7 @@
findings.json file" in html
assert "🎉 Clean Scan" not in html
+
+
+class _AnchorAttributeParser(HTMLParser):
+ def __init__(self) -> None:
+ super().__init__()
+ self.anchor_attrs: dict[str, str | None] = {}
+
+ def handle_starttag(
+ self,
+ tag: str,
+ attrs: list[tuple[str, str | None]],
+ ) -> None:
+ if tag == "a":
+ self.anchor_attrs = dict(attrs)
+
+
+def test_dashboard_external_links_warn_screen_readers() -> None:
+ """External links opening in new tabs must have accessible labels warning of context switch."""
+ html = _dashboard_html()
+
+ # Extract the literal anchor tag from the JS code
+ match = re.search(
+ r"const refs = [^`]+`(]+>)\$\{esc\(r\)\}`", html, re.DOTALL
+ )
+ assert match is not None
+ anchor_html = match.group(1) + ""
+
+ parser = _AnchorAttributeParser()
+ parser.feed(anchor_html)
+
+ assert parser.anchor_attrs.get("target") == "_blank"
+ assert parser.anchor_attrs.get("aria-label") == "${esc(r)} (opens in a new tab)"