Skip to content

Commit c5fed20

Browse files
authored
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.
1 parent 7e6f6fe commit c5fed20

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

internal/scan/probe.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package scan
1515
import (
1616
"context"
1717
"fmt"
18+
"html"
1819
"io"
1920
"net/http"
2021
"regexp"
@@ -133,13 +134,14 @@ func Probe(targetURL string, timeout time.Duration, logdir string) (*ProbeResult
133134
}
134135

135136
// extractTitle returns the trimmed text of the first <title> in body, or "" when
136-
// there isn't one.
137+
// there isn't one. html entities are decoded so the title matches the rendered
138+
// page rather than carrying raw "&amp;"-style markup.
137139
func extractTitle(body []byte) string {
138140
m := titleRe.FindSubmatch(body)
139141
if len(m) < 2 {
140142
return ""
141143
}
142-
return strings.TrimSpace(string(m[1]))
144+
return strings.TrimSpace(html.UnescapeString(string(m[1])))
143145
}
144146

145147
// ResultType identifies probe results for the result registry.

internal/scan/probe_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func TestProbe_ExtractTitle(t *testing.T) {
108108
{"trimmed", "<title> spaced </title>", "spaced"},
109109
{"attrs", `<title lang="en">attr</title>`, "attr"},
110110
{"multiline", "<title>line one\nline two</title>", "line one\nline two"},
111+
{"entities", "<title>Tom &amp; Jerry &#8211; Home</title>", "Tom & Jerry – Home"},
111112
{"none", "<html><body>no title</body></html>", ""},
112113
}
113114
for _, tt := range tests {

0 commit comments

Comments
 (0)