Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
fix(w3c/headers): error when license is unknown (speced#3806)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscaceres authored Oct 5, 2021
1 parent 92c9333 commit a25565d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/w3c/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,15 @@ export async function run(conf) {
const hint = docLink`Please set ${"[license]"} to "w3c-software-doc" instead.`;
showError(msg, name, { hint });
}
if (!licenses.has(conf.license)) {
const msg = `The license "\`${conf.license}\`" is not supported.`;
const choices = codedJoinOr(Array.from(licenses.keys()), {
quotes: true,
});
const hint = docLink`Please set
${"[license]"} to one of: ${choices}.`;
showError(msg, name, { hint });
}
conf.licenseInfo = licenses.get(conf.license);
conf.isCGBG = cgbgStatus.includes(conf.specStatus);
conf.isCGFinal = conf.isCGBG && conf.specStatus.endsWith("G-FINAL");
Expand Down
2 changes: 1 addition & 1 deletion src/w3c/seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async function addJSONLDInfo(conf, doc) {
type,
name: document.title,
inLanguage: doc.documentElement.lang || "en",
license: conf.licenseInfo.url,
license: conf.licenseInfo?.url,
datePublished: conf.dashDate,
/** @type {{ name: string, url?: string } | { name: string, url?: string }[]} */
copyrightHolder: {
Expand Down
15 changes: 15 additions & 0 deletions tests/spec/w3c/headers-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,21 @@ describe("W3C — Headers", () => {
});

describe("license configuration", () => {
it("shows and error when the license is unknown", async () => {
const ops = makeStandardOps({
specStatus: "WD",
license: "document",
github: "w3c/respec",
});
const doc = await makeRSDoc(ops, simpleSpecURL);
expect(doc.respec.errors).toHaveSize(1);
const [error] = doc.respec.errors;
expect(error.plugin).toBe("w3c/headers");
expect(error.message).toContain(
'The license "`document`" is not supported.'
);
});

it("defaults to cc-by when spec status is unofficial", async () => {
const ops = makeStandardOps({
shortName: "whatever",
Expand Down

0 comments on commit a25565d

Please sign in to comment.