Require src attribute when seeking snippet for verification (#4290)

This commit is contained in:
hq1 2024-07-01 07:38:25 +02:00 committed by GitHub
parent 8188006c45
commit f4e091452c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 2 deletions

View File

@ -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

View File

@ -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>