Skip to content

Commit

Permalink
Add Copyright exception config (#1720)
Browse files Browse the repository at this point in the history
* add json and test

* add test

* remove test

* move copyright exceptions under lib/ and add missing exceptions

* remove copyright exceptions as they are now being checked

* update checks

* fix copyright rule

* fix tests

---------

Co-authored-by: Denis Ah-Kang <[email protected]>
  • Loading branch information
jennyliang220 and deniak authored Mar 29, 2023
1 parent 5643e67 commit be40112
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"doasync",
"doctypes",
"dvcs",
"epub",
"epubcfi",
"ERCIM",
"exphbs",
"extractmetadataoptions",
Expand All @@ -29,6 +31,7 @@
"hellip",
"hilite",
"historyuri",
"Hickson",
"howto",
"Imple",
"implelink",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ $ W3C_API_KEY="<YOUR W3C API KEY>" npm start 3001
Set the environment variable `DEBUG` to run in _debug mode_ instead:

```bash
$ DEBUG=true W3C_API_KEY="<YOUR W3C API KEY>" npm start
$ DEBUG=true W3C_API_KEY="<YOUR W3C API KEY>" npm run start
```

This modifies the behaviour of certain parts of the application to facilitate debugging.
Expand Down
31 changes: 31 additions & 0 deletions lib/copyright-exceptions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[
{
"specShortnames": [
"epub-overview-33",
"epub-33",
"epub-rs-33",
"epub-multi-rend-11",
"epub-tts-10",
"epub-ssv-11",
"epub-a11y-11",
"epub-a11y-tech-11",
"epub-aria-authoring-11",
"epub-fxl-a11y",
"epubcfi",
"epubcfi-11"
],
"copyright": "<a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#Copyright\">Copyright</a> © 1999-@YEAR <a href=\"https://www.idpf.org\">International Digital Publishing Forum</a> and <a href=\"https://www.w3.org/\">World Wide Web Consortium</a>. <abbr title=\"World Wide Web Consortium\">W3C</abbr><sup>®</sup> <a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer\">liability</a>, <a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks\">trademark</a> and <a rel=\"license\" href=\"https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document\" title=\"W3C Software and Document Notice and License\">permissive document license</a> rules apply."
},
{
"specShortnames": ["webrtc"],
"copyright": "Initial Author of this Specification was Ian Hickson, Google Inc., with the following copyright statement:<br> © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and Opera Software ASA. You are granted a license to use, reproduce and create derivative works of this document. All subsequent changes since 26 July 2011 done by the W3C WebRTC Working Group are under the following <a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#Copyright\">Copyright</a>:<br> <a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#Copyright\">Copyright</a> © 2011-@YEAR <a href=\"https://www.w3.org/\">World Wide Web Consortium</a>. <abbr title=\"World Wide Web Consortium\">W3C</abbr><sup>®</sup> <a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer\">liability</a>, <a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks\">trademark</a> and <a href=\"https://www.w3.org/Consortium/Legal/copyright-documents\">document use</a> rules apply."
},
{
"specShortnames": ["security-privacy-questionnaire"],
"copyright": "<a href=\"http://creativecommons.org/publicdomain/zero/1.0/\" rel=\"license\"><img alt=\"CC0\" src=\"cc0-80x15.png\" title=\"CC0\"></a> To the extent possible under law, the editors have waived all copyright and related or neighboring rights to this work. This document is also made available under the <a href=\"https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document\" rel=\"license\">W3C Software and Document License</a>."
},
{
"specShortnames": ["mediacapture-streams"],
"copyright": "Initial Author of this Specification was Ian Hickson, Google Inc., with the following copyright statement:<br> © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and Opera Software ASA. You are granted a license to use, reproduce and create derivative works of this document."
}
]
15 changes: 0 additions & 15 deletions lib/exceptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,6 @@
"message": "Bad value “publication” for attribute “rel” on element “link”: The string “publication” is not a registered keyword."
}
],
"^webrtc$": [
{
"rule": "headers.copyright"
}
],
"^security-privacy-questionnaire$": [
{
"rule": "headers.copyright"
}
],
"^mediacapture-streams$": [
{
"rule": "headers.copyright"
}
],
"^audiobooks$": [
{
"rule": "sotd.candidate-review-end"
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n-en_GB.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export const messages = {
"This document is published by multiple groups, but these groups don't use the same document license. Please ask the team contact for help.",
'headers.copyright.no-license-found':
'Pubrules fails to find the document license in the group charter. Please ask the team contact for help.',
'headers.copyright.exception-no-html':
'The copyright used in this document <blockquote class="boilerplate">${copyright}</blockquote> does not match the requirements. The expected copyright is <blockquote class="boilerplate">${expected}</blockquote>',
'headers.memsub-copyright.not-found':
'Missing link to the W3C document notice (https://www.w3.org/Consortium/Legal/copyright-documents).',
// headers/github-repo
Expand Down
2 changes: 1 addition & 1 deletion lib/rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,7 @@
"editorSection": "The editors'/authors' names <span class=\"rfc2119\">must</span> be listed, with attribute <code>data-editor-id=\"@@\"</code>. Affiliations and email addresses are <span class=\"rfc2119\">optional</span>; email addresses are <span class=\"rfc2119\">not recommended</span>. If an editor/author is acknowledged in an earlier version of this document and the individual's affiliation has since changed, list the individual using the notation \"&lt;name&gt;, &lt;affiliation&gt; (until DD Month YYYY)\". If the list of authors is very long (e.g., the entire Working Group), identify the authors in the acknowledgments section, linked from the head of the document. Distinguish any contributors from authors in the acknowledgments section.",
"altRepresentations": "Authors <span class=\"rfc2119\">may</span> provide links to alternative (non-normative) representations or packages for the document. For instance: <p> <code> <small>&lt;p&gt;This document is also available in these non-normative formats: &lt;a href=\"@{param1}-shortname-20180101.html\"&gt;single HTML file&lt;/a&gt;, &lt;a href=\"@{param1}-shortname-20180101.tgz\"&gt;gzipped tar file of HTML&lt;/a&gt;.&lt;/p&gt; </small> </code> </p>",
"implReport": "It <span class=\"rfc2119\">must</span> include either: <ul> <li>a link to an interoperability or implementation report if the Director used such a report as part of the decision to advance the specification, or</li> <li>a statement that the Director's decision did not involve such a report.</li> </ul>",
"copyright": "Starting from 01 February 2023, the copyright <span class=\"rfc2119\">must</span> follow the following markup (fill in with the appropriate year, years, or year range). The type of license the document is using can be found in the group's charter. <ol> <li>For documents using W3C Document License: <blockquote class=\"copyright\"><a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#Copyright\">Copyright</a> © @{year} <a href=\"https://www.w3.org/\">World Wide Web Consortium</a>. <abbr title=\"World Wide Web Consortium\">W3C</abbr><sup>®</sup> <a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer\">liability</a>, <a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks\">trademark</a> and <a href=\"https://www.w3.org/Consortium/Legal/copyright-documents\">document use</a> rules apply.</blockquote><div class=\"source\"> <span style=\"font-style: italic\">Include this source code</span>:<br><code>&lt;p class=&quot;copyright&quot;&gt;&lt;a href=&quot;https://www.w3.org/Consortium/Legal/ipr-notice#Copyright&quot;&gt;Copyright&lt;/a&gt; © @{year} &lt;a href=&quot;https://www.w3.org/&quot;&gt;World Wide Web Consortium&lt;/a&gt;. &lt;abbr title=&quot;World Wide Web Consortium&quot;&gt;W3C&lt;/abbr&gt;&lt;sup&gt;®&lt;/sup&gt; &lt;a href=&quot;https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer&quot;&gt;liability&lt;/a&gt;, &lt;a href=&quot;https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks&quot;&gt;trademark&lt;/a&gt; and &lt;a href=\"https://www.w3.org/Consortium/Legal/copyright-documents\"&gt;document use&lt;/a&gt; rules apply.&lt;/p&gt;</code> </div></li><li>For documents using W3C Software and Document License: <blockquote class=\"copyright\"><a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#Copyright\">Copyright</a> © @{year} <a href=\"https://www.w3.org/\">World Wide Web Consortium</a>. <abbr title=\"World Wide Web Consortium\">W3C</abbr><sup>®</sup> <a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer\">liability</a>, <a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks\">trademark</a> and <a href=\"https://www.w3.org/Consortium/Legal/copyright-software\">permissive document license</a> rules apply.</blockquote><div class=\"source\"> <span style=\"font-style: italic\">Include this source code</span>:<br><code>&lt;p class=&quot;copyright&quot;&gt;&lt;a href=&quot;https://www.w3.org/Consortium/Legal/ipr-notice#Copyright&quot;&gt;Copyright&lt;/a&gt; © @{year} &lt;a href=&quot;https://www.w3.org/&quot;&gt;World Wide Web Consortium&lt;/a&gt;. &lt;abbr title=&quot;World Wide Web Consortium&quot;&gt;W3C&lt;/abbr&gt;&lt;sup&gt;®&lt;/sup&gt; &lt;a href=&quot;https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer&quot;&gt;liability&lt;/a&gt;, &lt;a href=&quot;https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks&quot;&gt;trademark&lt;/a&gt; and &lt;a href=&quot;https://www.w3.org/Consortium/Legal/copyright-software&quot;&gt;permissive document license&lt;/a&gt; rules apply.&lt;/p&gt;</code> </div></li></ol>",
"copyright": "Starting from 01 February 2023, the copyright <span class=\"rfc2119\">must</span> follow the following markup (fill in with the appropriate year, years, or year range). The type of license the document is using can be found in the group's charter. <ol> <li>For documents using W3C Document License: <blockquote class=\"copyright\"><a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#Copyright\">Copyright</a> © @{year} <a href=\"https://www.w3.org/\">World Wide Web Consortium</a>. <abbr title=\"World Wide Web Consortium\">W3C</abbr><sup>®</sup> <a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer\">liability</a>, <a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks\">trademark</a> and <a href=\"https://www.w3.org/Consortium/Legal/copyright-documents\">document use</a> rules apply.</blockquote><div class=\"source\"> <span style=\"font-style: italic\">Include this source code</span>:<br><code>&lt;p class=&quot;copyright&quot;&gt;&lt;a href=&quot;https://www.w3.org/Consortium/Legal/ipr-notice#Copyright&quot;&gt;Copyright&lt;/a&gt; © @{year} &lt;a href=&quot;https://www.w3.org/&quot;&gt;World Wide Web Consortium&lt;/a&gt;. &lt;abbr title=&quot;World Wide Web Consortium&quot;&gt;W3C&lt;/abbr&gt;&lt;sup&gt;®&lt;/sup&gt; &lt;a href=&quot;https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer&quot;&gt;liability&lt;/a&gt;, &lt;a href=&quot;https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks&quot;&gt;trademark&lt;/a&gt; and &lt;a href=\"https://www.w3.org/Consortium/Legal/copyright-documents\"&gt;document use&lt;/a&gt; rules apply.&lt;/p&gt;</code> </div></li><li>For documents using W3C Software and Document License: <blockquote class=\"copyright\"><a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#Copyright\">Copyright</a> © @{year} <a href=\"https://www.w3.org/\">World Wide Web Consortium</a>. <abbr title=\"World Wide Web Consortium\">W3C</abbr><sup>®</sup> <a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer\">liability</a>, <a href=\"https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks\">trademark</a> and <a href=\"https://www.w3.org/Consortium/Legal/copyright-software\">permissive document license</a> rules apply.</blockquote><div class=\"source\"> <span style=\"font-style: italic\">Include this source code</span>:<br><code>&lt;p class=&quot;copyright&quot;&gt;&lt;a href=&quot;https://www.w3.org/Consortium/Legal/ipr-notice#Copyright&quot;&gt;Copyright&lt;/a&gt; © @{year} &lt;a href=&quot;https://www.w3.org/&quot;&gt;World Wide Web Consortium&lt;/a&gt;. &lt;abbr title=&quot;World Wide Web Consortium&quot;&gt;W3C&lt;/abbr&gt;&lt;sup&gt;®&lt;/sup&gt; &lt;a href=&quot;https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer&quot;&gt;liability&lt;/a&gt;, &lt;a href=&quot;https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks&quot;&gt;trademark&lt;/a&gt; and &lt;a href=&quot;https://www.w3.org/Consortium/Legal/copyright-software&quot;&gt;permissive document license&lt;/a&gt; rules apply.&lt;/p&gt;</code> </div></li></ol><p>Note: Exceptions are listed in this <a href=\"https://github.com/w3c/specberus/blob/main/lib/copyright-exceptions.json\">json file</a>.",
"hrAfterCopyright": "A horizontal rule (<code>hr</code>) <span class=\"rfc2119\">must</span> follow the copyright."
}
},
Expand Down
45 changes: 41 additions & 4 deletions lib/rules/headers/copyright.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* 4. For "copyright-software", the url is https://www.w3.org/Consortium/Legal/copyright-software, the dated url is https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document, they are both allowed. The name in the API is "W3C Software and Document License", but the document would use text "permissive document license".
* 5. For "copyright-documents", the url is https://www.w3.org/Consortium/Legal/copyright-documents. The name in the API is "W3C Document License", but the document would use text "document use".
*/
import { AB, TAG } from '../../util.js';
import { AB, TAG, importJSON } from '../../util.js';

const self = {
name: 'headers.copyright',
Expand Down Expand Up @@ -43,6 +43,11 @@ const latestBaseLinks = {
trademark: 'https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks',
};

const copyrightExceptions = importJSON(
'../../copyright-exceptions.json',
import.meta.url
);

export const { name } = self;

async function isOnlyPublishedByTagOrAb(sr) {
Expand All @@ -60,12 +65,17 @@ function getCommonLicenseUri(data) {
.map(charter => charter['doc-licenses'].map(license => license.uri))
.reduce((first, cur) => first.filter(uri => cur.includes(uri)));
}

// The date can be 19xx-2023, or 2023.
function getLatestCopyrightMatchRegex(sr, licenseTexts) {
const licenseRex = licenseTexts.join('|');
const year = (sr.getDocumentDate() || new Date()).getFullYear();

const startRex = `^Copyright [©|&copy;] (?:(?:199\\d|20\\d\\d)-)?${year} *World Wide Web Consortium`;
const startRex =
'^Copyright [©|&copy;] (?:(?:199\\d|20\\d\\d)-)?@YEAR *World Wide Web Consortium'.replace(
'@YEAR',
year
);
const endRex = `\\. W3C[®|&reg;] liability, trademark,? and (${licenseRex}) rules apply\\.$`;
return new RegExp(startRex + endRex);
}
Expand Down Expand Up @@ -112,8 +122,26 @@ function checkCopyright(sr, copyright, licenseTexts, baseLinks, matchRegex) {
});
}

// Some documents like epub-33 uses special copyrights listed in copyright-exception.json
function checkSpecialCopyright(sr, copyright, specialCopyright, shortname) {
const year = (sr.getDocumentDate() || new Date()).getFullYear();

const domHtml = sr.norm(copyright.innerHTML);
const specHtml = sr.norm(
specialCopyright.copyright.replace(/@YEAR/g, year)
);
if (domHtml !== specHtml) {
sr.error(self, 'exception-no-html', {
copyright: domHtml,
expected: specHtml,
shortname,
});
}
}

function checkLatestCopyright(sr, copyright, licenseTexts) {
const matchRegex = getLatestCopyrightMatchRegex(sr, licenseTexts);

checkCopyright(sr, copyright, licenseTexts, latestBaseLinks, matchRegex);
}

Expand All @@ -128,7 +156,6 @@ export async function check(sr, done) {
sr.error(self, 'not-found');
return done();
}

if (await isOnlyPublishedByTagOrAb(sr)) {
return done();
}
Expand All @@ -154,7 +181,17 @@ export async function check(sr, done) {
.filter(v => [LICENSE_CD_URL, LICENSE_CS_URL].includes(v))
.map(v => LICENSE_URL_TEXT_MAP[v]);

checkLatestCopyright(sr, copyright, licenseTexts);
// get exception rule for certain shortnames
const shortname = await sr.getShortname();
const specialCopyright = copyrightExceptions.find(({ specShortnames }) =>
specShortnames.includes(shortname)
);

if (specialCopyright) {
checkSpecialCopyright(sr, copyright, specialCopyright, shortname);
} else {
checkLatestCopyright(sr, copyright, licenseTexts);
}

return done();
}
4 changes: 3 additions & 1 deletion test/doc-views/TR/Recommendation/WD.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ const customData = {
// Used in http://localhost:8001/doc-views/TR/Recommendation/WD?type=good
const good = { ...data, ...customData };

const commonData = buildCommonViewData(good);

export default {
good,
...buildCommonViewData(good),
...commonData,
'draft-stability': buildDraftStability(good),
'security-privacy': buildSecurityPrivacy(good),
};
3 changes: 3 additions & 0 deletions test/doc-views/layout/spec.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@
<a href="https://www.w3.org/Consortium/Legal/ipr-notice#Copyright">{{copyright.startText}}</a> © {{nowYear}} <a href="{{copyright.W3CLink}}"> World Wide Web Consortium</a>. <abbr title="World Wide Web Consortium">W3C</abbr><sup>®</sup> <a href="https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="https://www.w3.org/Consortium/Legal/copyright-software">permissive document license</a> rules apply.
</p>
{{/if}}
{{#if copyrightHtmlContent.show}}
{{{copyrightHtmlContent.html}}}
{{/if}}

{{#if header.hr.show}}
<hr title="Separator for header">
Expand Down
5 changes: 4 additions & 1 deletion test/doc-views/specBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ export const data = {
startText: 'Copyright',
W3CLink: 'https://www.w3.org/',
licenseHTML:
'<abbr title="World Wide Web Consortium">W3C</abbr><sup>®</sup> <a href="https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a rel="license" href="https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document">permissive document license</a> rules apply.',
'<abbr title="World Wide Web Consortium">W3C</abbr><sup>®</sup> <a href="https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a rel="license" href="https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document">permissive document license</a> rules apply',
},
copyrightHtmlContent: {
show: false,
},
abstract: {
abstractText: 'Abstract',
Expand Down

0 comments on commit be40112

Please sign in to comment.