mirror of
https://github.com/projectdiscovery/httpx
synced 2026-06-08 16:50:17 +00:00
Merge pull request #2293 from ayanrajpoot10/dev
Strip ANSI color codes from output file while keeping console colors
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
addReviewers: true
|
||||
reviewers:
|
||||
- dogancanbakir
|
||||
- dwisiswant0
|
||||
- mzack9999
|
||||
|
||||
numberOfReviewers: 1
|
||||
skipKeywords:
|
||||
- '@dependabot'
|
||||
+16
-1
@@ -101,6 +101,9 @@ func (r *Runner) HTTPX() *httpx.HTTPX {
|
||||
// picked based on try-fail but it seems to close to one it's used https://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html#c1992
|
||||
var hammingDistanceThreshold int = 22
|
||||
|
||||
// regex for stripping ANSI codes
|
||||
var ansiRegex = regexp.MustCompile(`\x1b\[[0-9;]*m`)
|
||||
|
||||
type pHashCluster struct {
|
||||
BasePHash uint64 `json:"base_phash,omitempty" csv:"base_phash"`
|
||||
Hashes []pHashUrl `json:"hashes,omitempty" csv:"hashes"`
|
||||
@@ -1180,7 +1183,7 @@ func (r *Runner) RunEnumeration() {
|
||||
|
||||
//nolint:errcheck // this method needs a small refactor to reduce complexity
|
||||
if plainFile != nil {
|
||||
plainFile.WriteString(resp.str + "\n")
|
||||
plainFile.WriteString(handleStripAnsiCharacters(resp.str, r.options.NoColor) + "\n")
|
||||
}
|
||||
|
||||
if len(r.options.ExcludeOutputFields) > 0 {
|
||||
@@ -1345,6 +1348,13 @@ func (r *Runner) RunEnumeration() {
|
||||
}
|
||||
}
|
||||
|
||||
func handleStripAnsiCharacters(data string, skip bool) string {
|
||||
if skip {
|
||||
return data
|
||||
}
|
||||
return stripANSI(data)
|
||||
}
|
||||
|
||||
func logFilteredErrorPage(fileName, url string) {
|
||||
dir := filepath.Dir(fileName)
|
||||
if !fileutil.FolderExists(dir) {
|
||||
@@ -2699,3 +2709,8 @@ func isWebSocket(resp *httpx.Response) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// stripANSI removes ANSI color codes from a string using pre-compiled regex
|
||||
func stripANSI(str string) string {
|
||||
return ansiRegex.ReplaceAllString(str, "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user