Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scripts/lint-artifact.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ function lintOne(file) {

// --- clipboard guard ---
if (/navigator\.clipboard\.writeText/.test(html)) {
const hasHelper = /(?:const|function|let|var)\s+writeClipboard\b/.test(html);
if (!hasHelper) fails.push("navigator.clipboard.writeText appears without a writeClipboard helper in the same file");
const guarded = /navigator\.clipboard\s*&&\s*navigator\.clipboard\.writeText|navigator\.clipboard\?\.writeText/.test(html);
if (!guarded) fails.push("navigator.clipboard.writeText called without guarding navigator.clipboard first");
}
Expand Down
29 changes: 29 additions & 0 deletions tests/test_linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,35 @@ def test_lint_artifact_against_dropped_copy_prompt_fails(tmp_path):
assert "copy-as-prompt" in r.stdout


def test_lint_artifact_unguarded_clipboard_fails(tmp_path):
bad = tmp_path / "unguarded.html"
bad.write_text(
_META_HEAD
+ '<svg></svg><input type="search"><table></table>'
+ "<script>navigator.clipboard.writeText('x');</script>"
+ "</body></html>"
)
r = _run("scripts/lint-artifact.mjs", str(bad))
assert r.returncode == 1
assert "writeClipboard" in r.stdout or "guard" in r.stdout.lower()


def test_lint_artifact_writeClipboard_helper_passes(tmp_path):
ok = tmp_path / "helper.html"
ok.write_text(
_META_HEAD
+ '<svg></svg><input type="search"><table></table>'
+ "<script>"
+ "const writeClipboard = (t) => navigator.clipboard?.writeText"
+ " ? navigator.clipboard.writeText(t)"
+ " : Promise.reject(new Error('clipboard unavailable'));"
+ "writeClipboard('x');"
+ "</script></body></html>"
)
r = _run("scripts/lint-artifact.mjs", str(ok))
assert r.returncode == 0, r.stdout + r.stderr


def test_lint_artifact_against_dropped_script_fails(tmp_path):
src = (REPO / "examples" / "dashboard.html").read_text()
bad = tmp_path / "dropped-script.html"
Expand Down
Loading