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

Introducing CanHaveTitleTag Function for MIME Type Validation #1608

Merged
merged 14 commits into from
Mar 23, 2024
Merged
19 changes: 19 additions & 0 deletions common/httpx/title.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ func ExtractTitle(r *Response) (title string) {
return title
}

func CanHaveTitleTag(mimeType string) bool {
mimeTypes := []string{
RedYetiDev marked this conversation as resolved.
Show resolved Hide resolved
"text/html",
"application/xhtml+xml",
"application/xml",
"application/rss+xml",
"application/atom+xml",
"application/xhtml+xml",
"application/vnd.wap.xhtml+xml",
}

for _, mt := range mimeTypes {
if strings.EqualFold(mt, mimeType) {
return true
}
}
return false
}

func getTitleWithDom(r *Response) (*html.Node, error) {
var title *html.Node
var crawler func(*html.Node)
Expand Down
5 changes: 4 additions & 1 deletion runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -1589,8 +1589,11 @@
}
builder.WriteRune(']')
}
title := nil

Check failure on line 1592 in runner/runner.go

View workflow job for this annotation

GitHub Actions / release-test

use of untyped nil in assignment

Check failure on line 1592 in runner/runner.go

View workflow job for this annotation

GitHub Actions / Lint Test

use of untyped nil in assignment) (typecheck)

Check failure on line 1592 in runner/runner.go

View workflow job for this annotation

GitHub Actions / Lint Test

use of untyped nil in assignment) (typecheck)

Check failure on line 1592 in runner/runner.go

View workflow job for this annotation

GitHub Actions / Lint Test

use of untyped nil in assignment (typecheck)
RedYetiDev marked this conversation as resolved.
Show resolved Hide resolved
if httpx.CanHaveTitleTag(resp.GetHeaderPart("Content-Type", ";")) {
title = httpx.ExtractTitle(resp)
}

title := httpx.ExtractTitle(resp)
if scanopts.OutputTitle {
builder.WriteString(" [")
if !scanopts.OutputWithNoColor {
Expand Down
Loading