Skip to content

Commit 12cca55

Browse files
Fix report link safety and conditional cycle map navigation
Preserve ordered-list start attributes, add regression coverage, and qualify WCAG compliance claims.
1 parent 49b4969 commit 12cca55

7 files changed

Lines changed: 53 additions & 16 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ is a **Next.js static export** (`bun run build` produces `out/`, which any stati
1515
platform account is captured as the issue author and validated server-side by the platform's CI
1616
- Reports and submissions work for repositories hosted on the same platform as the deployment (GitHub, GitLab or
1717
Bitbucket)
18-
- **Accessible**: the site and the rendered reports comply with **WCAG 2.2 AA** (semantic HTML5, visible focus
19-
indicators, AA color contrast, per-page titles, table captions and scoped headers, labeled controls and landmarks)
18+
- **Accessible**: the site and rendered reports target **WCAG 2.2 AA**, with automated checks for selected requirements
19+
such as semantic HTML5, color contrast, per-page titles, table semantics, labeled controls and landmarks
2020
- Works with a plain static file server: `python3 -m http.server 8000`
2121

2222
---
@@ -374,7 +374,7 @@ bun run test:e2e:basepath # NEXT_PUBLIC_BASE_PATH=/preview leg (chromium)
374374

375375
### Accessibility (WCAG 2.2 AA)
376376

377-
This application complies with **WCAG 2.2 Level AA**, and every change must keep it that way: the dedicated guards in
377+
This application targets **WCAG 2.2 Level AA**. Dedicated guards cover selected requirements:
378378
`tests/unit/html5-attributes.test.js`, `tests/unit/report-template-wcag.test.js`, `tests/unit/css-a11y.test.js` and
379379
`tests/unit/page-titles.test.js` verify HTML5-valid markup (no obsolete presentational attributes), semantic heading
380380
hierarchy, table captions and scoped headers, chart alternative text, landmark names, color contrast, focus visibility,

‎assets/refactor-first-report.mustache‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@
159159
<li><a href="#CYCLES">Cycles</a>
160160
<ul>
161161
<li><a href="#CYCLES">Class Cycles</a></li>
162+
{{#classCycles.largestCycle.hasCycleMap}}
162163
<li><a href="#CYCLEMAP">Cycle Map</a></li>
164+
{{/classCycles.largestCycle.hasCycleMap}}
163165
</ul>
164166
</li>
165167
{{/classCycles.hasCycles}}

‎lib/renderer.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let linkSafetyHookRegistered = false;
2727
function registerLinkSafetyHook() {
2828
if (linkSafetyHookRegistered || typeof DOMPurify.addHook !== 'function') return;
2929
DOMPurify.addHook('afterSanitizeAttributes', node => {
30-
if (node.tagName === 'A' && node.getAttribute('target') === '_blank') {
30+
if (node.tagName === 'A' && node.getAttribute('target')?.trim().toLowerCase() === '_blank') {
3131
node.setAttribute('rel', 'noopener noreferrer');
3232
}
3333
});
@@ -79,7 +79,7 @@ export function renderTemplate(template, data) {
7979
'align', 'alink', 'background', 'bgcolor', 'border', 'char', 'charoff',
8080
'clear', 'compact', 'frame', 'frameborder', 'hspace', 'link',
8181
'marginheight', 'marginwidth', 'noshade', 'noresize', 'rules',
82-
'scrolling', 'start', 'text', 'valign', 'vlink', 'vspace'
82+
'scrolling', 'text', 'valign', 'vlink', 'vspace'
8383
],
8484
FORBID_TAGS: ['script', 'iframe', 'object', 'embed', 'meta', 'link', 'form', 'input', 'select', 'textarea'],
8585
FORCE_BODY: true

‎public/assets/refactor-first-report.mustache‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@
159159
<li><a href="#CYCLES">Cycles</a>
160160
<ul>
161161
<li><a href="#CYCLES">Class Cycles</a></li>
162+
{{#classCycles.largestCycle.hasCycleMap}}
162163
<li><a href="#CYCLEMAP">Cycle Map</a></li>
164+
{{/classCycles.largestCycle.hasCycleMap}}
163165
</ul>
164166
</li>
165167
{{/classCycles.hasCycles}}

‎tests/unit/html5-attributes.test.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const OBSOLETE_ATTRIBUTES = [
1818
'align', 'alink', 'background', 'bgcolor', 'border', 'char', 'charoff',
1919
'clear', 'compact', 'frame', 'frameborder', 'hspace', 'link',
2020
'marginheight', 'marginwidth', 'noshade', 'noresize', 'rules', 'scrolling',
21-
'start', 'text', 'valign', 'vlink', 'vspace'
21+
'text', 'valign', 'vlink', 'vspace'
2222
];
2323

2424
// Every file that contributes markup: the report template, the workflow
@@ -70,6 +70,13 @@ describe('HTML5 attribute compliance (sources)', () => {
7070
expect(html).toContain('<table>');
7171
expect(html).toContain('<td>');
7272
});
73+
74+
it('preserves valid ordered-list numbering', () => {
75+
const html = renderTemplate('<ol start="3"><li>Third</li></ol>', {});
76+
const list = new JSDOM(html).window.document.querySelector('ol');
77+
78+
expect(list?.getAttribute('start')).toBe('3');
79+
});
7380
});
7481

7582
describe('HTML5 attribute compliance (rendered report)', () => {

‎tests/unit/renderer.test.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, it, expect } from 'bun:test';
2+
import { JSDOM } from 'jsdom';
23
import { renderTemplate, initializeMustache } from '../../lib/renderer.js';
34

45
describe('Mustache Rendering', () => {
@@ -112,6 +113,21 @@ describe('templating safety (repository-provided templates are untrusted)', () =
112113
expect(html).toContain('<img');
113114
});
114115

116+
it('normalizes target values before securing new browsing contexts', () => {
117+
const html = renderTemplate(
118+
'<a href="https://example.com" target=" _BlAnK ">New tab</a>' +
119+
'<a href="https://example.com/same" target="_self">Same tab</a>' +
120+
'<div target="_blank">Not a link</div>',
121+
{}
122+
);
123+
const document = new JSDOM(html).window.document;
124+
125+
expect(document.querySelector('a[href="https://example.com"]')?.getAttribute('rel'))
126+
.toBe('noopener noreferrer');
127+
expect(document.querySelector('a[target="_self"]')?.hasAttribute('rel')).toBe(false);
128+
expect(document.querySelector('div[target="_blank"]')?.hasAttribute('rel')).toBe(false);
129+
});
130+
115131
it('keeps benign structure, style attributes and data attributes intact', () => {
116132
const html = renderTemplate(
117133
'<div id="popup-classGraph" style="width: 100%;"><span class="close-btn">&times;</span></div>',

‎tests/unit/report-template-wcag.test.js‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,27 @@ describe('report template WCAG 2.2 AA (rendered with fixture data)', () => {
9292
});
9393

9494
it('in-page navigation links resolve to actual targets', () => {
95-
const violations = [];
96-
for (const anchor of doc.querySelectorAll('a[href^="#"]')) {
97-
const target = anchor.getAttribute('href');
98-
if (target === '#') {
99-
violations.push(`placeholder link "${anchor.textContent.trim()}"`);
100-
continue;
101-
}
102-
if (!doc.getElementById(target.slice(1))) {
103-
violations.push(`unresolved anchor ${target}`);
95+
const fixtureWithoutCycleMap = structuredClone(fixture);
96+
fixtureWithoutCycleMap.classCycles.largestCycle.hasCycleMap = false;
97+
const docWithoutCycleMap = new JSDOM(
98+
renderTemplate(template, fixtureWithoutCycleMap)
99+
).window.document;
100+
101+
for (const renderedDoc of [doc, docWithoutCycleMap]) {
102+
const violations = [];
103+
for (const anchor of renderedDoc.querySelectorAll('a[href^="#"]')) {
104+
const target = anchor.getAttribute('href');
105+
if (target === '#') {
106+
violations.push(`placeholder link "${anchor.textContent.trim()}"`);
107+
continue;
108+
}
109+
if (!renderedDoc.getElementById(target.slice(1))) {
110+
violations.push(`unresolved anchor ${target}`);
111+
}
104112
}
113+
expect(violations).toEqual([]);
105114
}
106-
expect(violations).toEqual([]);
115+
116+
expect(docWithoutCycleMap.querySelector('a[href="#CYCLEMAP"]')).toBeNull();
107117
});
108118
});

0 commit comments

Comments
 (0)