Skip to content
Open
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
6 changes: 4 additions & 2 deletions internal/scan/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package scan
import (
"context"
"fmt"
"html"
"io"
"net/http"
"regexp"
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions internal/scan/probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading