Skip to content

feat(w3c/headers): validate header links#5143

Open
marcoscaceres wants to merge 4 commits intomainfrom
feat/validate-header-links
Open

feat(w3c/headers): validate header links#5143
marcoscaceres wants to merge 4 commits intomainfrom
feat/validate-header-links

Conversation

@marcoscaceres
Copy link
Copy Markdown
Contributor

Summary

  • Validates that edDraftURI, historyURI, implementationReportURI, and other header links are well-formed URLs pointing to the expected hosts
  • Rejects obviously wrong values early with clear error messages rather than silently producing broken spec headers

Test plan

  • Run integration tests: pnpm test:integration
  • Verify error messages appear for invalid header link values

@marcoscaceres marcoscaceres force-pushed the feat/validate-header-links branch 2 times, most recently from bb1051e to 5982fb1 Compare March 28, 2026 12:09
- Warn if latestVersion URL doesn't resolve (non-FPWD docs)
- CG drafts (specStatus ending in -DRAFT) no longer require latestVersion
- Extract resourceExists() helper that returns the final URL after
  redirects (or null), replacing ad-hoc fetch+ok patterns
- deriveHistoryURI() now returns a value instead of mutating conf,
  and uses resourceExists() to avoid duplicating fetch logic
- Guard conf.historyURI = null (user suppression) at the call site
  so explicit null is not overwritten by derivation
- Fix URL construction: use response.url (post-redirect) for the
  history URL rather than the pre-redirect constructed URL

Fixes #4037 (rebased from validate_latest branch)
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances W3C header handling by adding validation/verification around key header links (notably latestVersion and historyURI) and extends the test suite to cover the new behaviors, aiming to surface broken header links earlier via warnings/errors.

Changes:

  • Add a HEAD check for derived latestVersion URLs and emit a w3c/headers warning when the URL can’t be reached.
  • Adjust historyURI derivation to support explicit suppression (null) and refactor URL probing into resourceExists().
  • Update/extend w3c/headers tests (warnings filter, status loops, new warning expectation).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
tests/spec/w3c/headers-spec.js Adds warnings assertions and refactors status-based tests for header link behavior.
src/w3c/templates/cgbg-headers.js Tweaks when the “Latest published version” row is rendered for CG/BG headers.
src/w3c/headers.js Adds URL existence probing for latestVersion, refactors history derivation, and introduces resourceExists().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Fix [shortname] → [shortName] in docLink hint (wrong casing)
- Move FPWD guard before resourceExists() fetch to avoid unnecessary
  network request for FPWD docs
- Return null (not conf.historyURI) when historyURI is set on a
  non-standards-track document, so the History link is not rendered
- Use cgbgStatus (not cgStatus) in the latestVersion loop test to
  cover BG-DRAFT status
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/w3c/templates/cgbg-headers.js:47

  • conf.latestVersion !== null (and the nested conf.latestVersion !== "") will treat undefined as “present” and render an <a> whose href/text become undefined. The W3C headers template avoids this by checking property existence ("latestVersion" in conf) and then treating falsy values as “none”. Consider aligning the CGBG template logic (e.g., guard on property existence or use a nullish check) so missing/undefined latestVersion can’t produce a broken link.
      ${conf.latestVersion !== null
        ? html`<dt>${l10n.latest_published_version}</dt>
            <dd>
              ${conf.latestVersion !== ""
                ? html`<a href="${conf.latestVersion}"
                    >${conf.latestVersion}</a
                  >`
                : "none"}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

</dd>`
: ""}
${"latestVersion" in conf // latestVersion can be falsy
${conf.latestVersion !== null
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Check for undefined as well?

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.

3 participants