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

New line with title flag #448

Merged
merged 2 commits into from
Nov 30, 2021
Merged
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
26 changes: 26 additions & 0 deletions cmd/integration-test/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var httpTestcases = map[string]testutils.TestCase{
"Regression test for: https://github.com/projectdiscovery/httpx/issues/303": &issue303{}, // misconfigured gzip header with uncompressed body
"Regression test for: https://github.com/projectdiscovery/httpx/issues/400": &issue400{}, // post operation with body
"Regression test for: https://github.com/projectdiscovery/httpx/issues/414": &issue414{}, // stream mode with path
"Regression test for: https://github.com/projectdiscovery/httpx/issues/433": &issue433{}, // new line scanning with title flag
}

type standardHttpGet struct {
Expand Down Expand Up @@ -238,3 +239,28 @@ func (h *issue414) Execute() error {
}
return nil
}

type issue433 struct{}

func (h *issue433) Execute() error {
var ts *httptest.Server
router := httprouter.New()
uriPath := "/index"
router.GET(uriPath, httprouter.Handle(func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
htmlResponse := "<html><head><title>Project\n\r Discovery\n - Httpx></title></head><body>test data</body></html>"
fmt.Fprint(w, htmlResponse)
}))
ts = httptest.NewServer(router)
defer ts.Close()
results, err := testutils.RunHttpxAndGetResults(fmt.Sprint(ts.URL, uriPath), debug, "-title", "-no-color")
if err != nil {
return err
}
if strings.Contains(results[0], "\n") {
return errIncorrectResultsCount(results)
}
if strings.Contains(results[0], "\r") {
return errIncorrectResultsCount(results)
}
return nil
}
2 changes: 2 additions & 0 deletions common/httpx/title.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func ExtractTitle(r *Response) (title string) {

// remove unwanted chars
title = strings.TrimSpace(strings.Trim(title, cutset))
title = strings.ReplaceAll(title, "\n", "")
title = strings.ReplaceAll(title, "\r", "")

// Non UTF-8
if contentTypes, ok := r.Headers["Content-Type"]; ok {
Expand Down