aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhackademix <giorgio@maone.net>2019-02-25 13:05:26 +0100
committerhackademix <giorgio@maone.net>2019-02-25 13:05:26 +0100
commitee895dd3e5e9fd743f6980f57008ce28b71c3bb0 (patch)
tree81e3acfa256ef0711065c4a4966fe65cd7d9d205
parentc80d6d7f2842e7e07bd2b070d975f898f23b54dd (diff)
Test for inline scripts in attributes, including (de)duplication.
-rw-r--r--test/spec/LibreJSSpec.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/spec/LibreJSSpec.js b/test/spec/LibreJSSpec.js
index 3d61973..57c7f65 100644
--- a/test/spec/LibreJSSpec.js
+++ b/test/spec/LibreJSSpec.js
@@ -94,6 +94,10 @@ describe("LibreJS' components", () => {
let addScript = (html, script, before = "</head>") =>
html.replace(before, `<script>${script}</script>${before}`);
+ let addToBody = (html, fragment) => html.replace("</body>", `${fragment}</body>`);
+
+ let jsUrl = js => `javascript:${encodeURIComponent(js)}`;
+
function extractScripts(html, def = "") {
let matches = html && html.match(/<script>[^]*?<\/script>/g);
return matches && matches.join("") || def;
@@ -165,6 +169,21 @@ describe("LibreJS' components", () => {
expect(scripts).toContain(licensed);
expect(scripts.replace(licensed, "")).not.toContain(nontrivial);
});
+
+ it("should correctly process (de)duplicated inline scripts", async () => {
+ let trivialAsUrl = jsUrl(trivial);
+ let nontrivialAsUrl = jsUrl(nontrivial);
+ let a = (url, label) => `<a href="${url}">${label}</a>`;
+ let mixedPage = `<body></body>`;
+ for (let dup = 0; dup < 3; dup++) {
+ mixedPage = addToBody(mixedPage, a(trivialAsUrl, `Trivial #${dup}`));
+ mixedPage = addToBody(mixedPage, a(nontrivialAsUrl, `Nontrivial #${dup}`));
+ }
+ let processed = await processHtml(mixedPage);
+ expect(processed).not.toBeNull();
+ expect(processed).toContain(trivialAsUrl);
+ expect(processed).not.toContain(nontrivialAsUrl);
+ });
});
describe("The external (Web Labels) license checker", () => {