Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require src attribute when seeking snippet for verification #4290

Merged
merged 2 commits into from
Jul 1, 2024
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
4 changes: 2 additions & 2 deletions lib/plausible/verification/checks/snippet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ defmodule Plausible.Verification.Checks.Snippet do

@impl true
def perform(%State{assigns: %{document: document}} = state) do
in_head = Floki.find(document, "head script[data-domain]")
in_body = Floki.find(document, "body script[data-domain]")
in_head = Floki.find(document, "head script[data-domain][src]")
in_body = Floki.find(document, "body script[data-domain][src]")

all = in_head ++ in_body

Expand Down
20 changes: 20 additions & 0 deletions test/plausible/site/verification/checks_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,26 @@ defmodule Plausible.Verification.ChecksTest do
|> assert_error(@errors.multiple_snippets)
end

@no_src_scripts """
<html>
<head>
<script defer data-domain="example.com"></script>
</head>
<body>
Hello
<script defer data-domain="example.com"></script>
</body>
</html>
"""
test "no src attr doesn't count as snippet" do
stub_fetch_body(200, @no_src_scripts)
stub_installation(200, plausible_installed(false))

run_checks()
|> Checks.interpret_diagnostics()
|> assert_error(@errors.no_snippet)
end

@many_snippets_ok """
<html>
<head>
Expand Down