fix(scan): decode html entities in probe title (#354)

the probe title field is documented as an httpx-style page title, but
extractTitle returned the raw regex capture, so a title like
"Tom & Jerry" was reported verbatim instead of "Tom & Jerry".
run it through html.UnescapeString before trimming so the reported
title matches the rendered page.
This commit is contained in:
Tigah
2026-07-22 12:56:38 -07:00
committed by GitHub
parent 7e6f6fe2e6
commit c5fed20d86
2 changed files with 5 additions and 2 deletions
+4 -2
View File
@@ -15,6 +15,7 @@ package scan
import (
"context"
"fmt"
"html"
"io"
"net/http"
"regexp"
@@ -133,13 +134,14 @@ func Probe(targetURL string, timeout time.Duration, logdir string) (*ProbeResult
}
// extractTitle returns the trimmed text of the first <title> in body, or "" when
// there isn't one.
// there isn't one. html entities are decoded so the title matches the rendered
// page rather than carrying raw "&amp;"-style markup.
func extractTitle(body []byte) string {
m := titleRe.FindSubmatch(body)
if len(m) < 2 {
return ""
}
return strings.TrimSpace(string(m[1]))
return strings.TrimSpace(html.UnescapeString(string(m[1])))
}
// ResultType identifies probe results for the result registry.
+1
View File
@@ -108,6 +108,7 @@ func TestProbe_ExtractTitle(t *testing.T) {
{"trimmed", "<title> spaced </title>", "spaced"},
{"attrs", `<title lang="en">attr</title>`, "attr"},
{"multiline", "<title>line one\nline two</title>", "line one\nline two"},
{"entities", "<title>Tom &amp; Jerry &#8211; Home</title>", "Tom & Jerry Home"},
{"none", "<html><body>no title</body></html>", ""},
}
for _, tt := range tests {