Skip to content

fix(w3c): flag a /TR/-track specStatus rendered off w3.org/TR - #5469

Open
pchampin wants to merge 1 commit into
speced:mainfrom
pchampin:fix5468
Open

pchampin wants to merge 1 commit into
speced:mainfrom
pchampin:fix5468

Conversation

@pchampin

Copy link
Copy Markdown

fix #5468

  • src/w3c/headers.js: new exported pure function isOffTR(specStatus, href) returns true when specStatus is one of the formal /TR/-track statuses (trStatus — Notes, Rec-track, Registry-track) but href isn't under https://www.w3.org/TR/ (or the w3.org alias). A wrapper, validateRenderingLocation, calls this with document.location.href and raises a pill error (via showError) unless: the current frame isn't the top-level browsing context (so test harnesses and embedded preview panes are unaffected), or specStatus was itself overridden via a ?specStatus= query parameter (the existing local-preview mechanism from core/override-configuration.js).

  • Statuses like ED, unofficial, base, CG/BG reports, etc. are unaffected — only the statuses that actually generate a w3.org/TR "this version" URL are checked, matching the bug the issue described (a broken "This version" link when e.g. specStatus: WD is deployed on GitHub Pages).

  • Added tests/unit/w3c/headers-spec.js with unit tests directly exercising isOffTR (fast path, no DOM/iframe needed, since the integration harness always runs inside an iframe where the new check intentionally no-ops).

  • Verified: pnpm lint clean, full unit suite (93 tests) and integration suite (1160 tests) pass with zero failures, and confirmed no example/headless fixtures use a status that would trip the new check.

fix speced#5468

- src/w3c/headers.js: new exported pure function isOffTR(specStatus, href)
  returns true when specStatus is one of the formal /TR/-track statuses
  (trStatus — Notes, Rec-track, Registry-track) but href isn't under
  https://www.w3.org/TR/ (or the w3.org alias).
  A wrapper, validateRenderingLocation, calls this with
  document.location.href and raises a pill error (via showError) unless:
  the current frame isn't the top-level browsing context (so test
  harnesses and embedded preview panes are unaffected), or specStatus was
  itself overridden via a ?specStatus= query parameter (the existing
  local-preview mechanism from core/override-configuration.js).

- Statuses like ED, unofficial, base, CG/BG reports, etc. are unaffected
  — only the statuses that actually generate a w3.org/TR "this version"
  URL are checked, matching the bug the issue described (a broken "This
  version" link when e.g. specStatus: WD is deployed on GitHub Pages).

- Added tests/unit/w3c/headers-spec.js with unit tests directly exercising
  isOffTR (fast path, no DOM/iframe needed, since the integration harness
  always runs inside an iframe where the new check intentionally no-ops).

- Verified: pnpm lint clean, full unit suite (93 tests) and integration
  suite (1160 tests) pass with zero failures, and confirmed no
  example/headless fixtures use a status that would trip the new check.
Comment thread src/w3c/headers.js
if (!trStatus.includes(specStatus)) {
return false;
}
let url;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can probably use URL.canParse(href) to cut down the five lines...

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The validation has bypass and status-coverage gaps, and its user-visible path is untested.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds validation to prevent formal W3C publication statuses from being rendered outside the /TR/ publication space.

Changes:

  • Adds publication-location validation with preview and iframe exemptions.
  • Adds a reusable URL/status helper.
  • Adds unit tests for the helper.
File summaries
File Description
tests/unit/w3c/headers-spec.js Tests status and publication URL combinations.
src/w3c/headers.js Validates formal status rendering locations.
Review details

Suppressed comments (2)

src/w3c/headers.js:707

  • The suggested URL is invalid when the page already has query parameters: appending ?specStatus=... after an existing ?foo=... does not create a specStatus parameter. Describe it as adding a query parameter so users can use the appropriate ? or & delimiter.
  const hint = docLink`W3C documents with a status of \`"${specStatus}"\` must be published under \`https://www.w3.org/TR/\`. Set ${"[specStatus]"} to \`"ED"\` for the Editor's Draft, or append \`?specStatus=${specStatus}\` to the URL to preview this status locally without changing the source.`;

tests/unit/w3c/headers-spec.js:7

  • Both newly added loops use for...of, contrary to this repository's stated preference for functional iteration. Use forEach for both status lists.
    for (const specStatus of ["ED", "unofficial", "base", "CG-DRAFT", "MO"]) {
  • Files reviewed: 2/2 changed files
  • Comments generated: 3
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/w3c/headers.js
* @param {string} href window.location.href of the document being rendered
*/
export function isOffTR(specStatus, href) {
if (!trStatus.includes(specStatus)) {
Comment thread src/w3c/headers.js
Comment on lines +700 to +702
const specStatusOverridden = new URLSearchParams(
document.location.search
).has("specStatus");
Comment thread src/w3c/headers.js
Comment on lines +696 to +703
function validateRenderingLocation(specStatus) {
if (window.parent !== window.self) {
return;
}
const specStatusOverridden = new URLSearchParams(
document.location.search
).has("specStatus");
if (specStatusOverridden || !isOffTR(specStatus, document.location.href)) {
Comment thread src/w3c/headers.js
} catch {
return false;
}
const isOnTR =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check seems a bit un-elegant to be honest... my (limited) testing seems to suggest that it always redirects to https://www.w3.org/TR/, so maybe always just checks that it startsWith()? Or is there cases where https://w3.org/TR/ can occur?

Comment thread src/w3c/headers.js
* @param {string} specStatus
* @param {string} href window.location.href of the document being rendered
*/
export function isOffTR(specStatus, href) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exporting this just to test it doesn't seem great, to be honest... what would be better is just create any document (like the rest of the tests do)... they all run on localhost and will violate this policy.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

W3C specStatus should raise an error when not on w3.org/TR/

3 participants