diff options
author | Yuchen Pei <hi@ypei.me> | 2022-10-13 15:48:44 +1100 |
---|---|---|
committer | Yuchen Pei <hi@ypei.me> | 2022-10-13 15:48:44 +1100 |
commit | dbfe1fb86719a18364f24bff57781aeb3262cb90 (patch) | |
tree | 17ba57546ed7884f44a1610e01a1f10b3207149c /test/spec/LibreJSSpec.js | |
parent | 388b1b9218a5f8971b6c1cdeb9cfa67940e1d33e (diff) |
fixing a few problems with @license / @license-end regexes
- trailing whitespace, including newlines are consumed by the opneing
regex (added a test case)
- added a test case for /* @license ... */ ... /* @license-end */
Diffstat (limited to 'test/spec/LibreJSSpec.js')
-rw-r--r-- | test/spec/LibreJSSpec.js | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/spec/LibreJSSpec.js b/test/spec/LibreJSSpec.js index 7e21c24..bbd699c 100644 --- a/test/spec/LibreJSSpec.js +++ b/test/spec/LibreJSSpec.js @@ -41,12 +41,16 @@ describe('LibreJS\' components', () => { // code calling anything else is trivial const trivialCall = 'foo();'; const licensed = `// @license ${license.magnet} ${license.id}\n${nontrivial}\n// @license-end`; + const licensedStarCommented = `/* @license ${license.magnet} ${license.id} */${nontrivial}/* @license-end */`; const unknownLicensed = `// @license ${unknownLicense.magnet} ${unknownLicense.id}\n${nontrivial}\n// @license-end`; const commentedOutUnknownLicensed = unknownLicensed.split('\n').map(y => '// ' + y).join('\n'); const malformedLicensed = `// @license\n${nontrivial}`; const commentedOutMalformedLicensed = malformedLicensed.split('\n').map(y => '// ' + y).join('\n'); + const emptyLicensed = `// @license ${license.magnet} ${license.id}\n// @license-end`; + const licensedNontrivialTrivial = `${emptyLicensed}\n${nontrivial}\n${trivial}`; + let tab, documentUrl; const enableContactFinderTests = false; @@ -121,6 +125,8 @@ describe('LibreJS\' components', () => { it('should accept scripts with known free license tags', async () => { const processed = await processScript(licensed); expect(processed || licensed).toContain(nontrivial); + const processed1 = await processScript(licensedStarCommented); + expect(processed1 || licensed).toContain(nontrivial); }); it('should block scripts with unknown license tags', async () => { @@ -210,6 +216,12 @@ describe('LibreJS\' components', () => { expect(extractScripts(processed, nontrivial)).not.toContain(nontrivial); }); + it('should block the unlicensed nontrivial part sandwiched between licensed and trivial parts', async () => { + const modifiedHtml = addScript(html, licensedNontrivialTrivial); + const processed = await processHtml(modifiedHtml); + expect(extractScripts(processed, nontrivial)).not.toContain(nontrivial); + }); + it('should accept scripts on globally licensed pages', async () => { const globalLicense = `/* @licstart The following is the entire license notice for the JavaScript code in this page. |