Skip to content

Commit

Permalink
Merge pull request #448 from projectdiscovery/new-line-with-title-flag
Browse files Browse the repository at this point in the history
New line with title flag
  • Loading branch information
ehsandeep authored Nov 30, 2021
2 parents 8d82b65 + 69b0bb5 commit 162cd4b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
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

0 comments on commit 162cd4b

Please sign in to comment.