Skip to content

Commit

Permalink
Merge pull request #21 from assetnote/gh-issue-13-visual-basepath-bug
Browse files Browse the repository at this point in the history
fix(cli-scan): avoid double appending / in the basepath and route path in output
  • Loading branch information
minight authored Apr 16, 2021
2 parents 4e73307 + c82280f commit 5c48bef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions internal/scan/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ func TestParseDomain(t *testing.T) {
}{
{"simple", args{"foo.com"}, []*http.Target{{IsTLS: true, Hostname: "foo.com", Port: 443}, {Hostname: "foo.com", Port: 80}}, false},
{"full uri", args{"https://foo.com"}, []*http.Target{{IsTLS: true, Hostname: "foo.com", Port: 443}}, false},
{"full uri trailing slash", args{"https://foo.com/"}, []*http.Target{{IsTLS: true, Hostname: "foo.com", Port: 443, BasePath: "/"}}, false},
{"full uri trailing slash subdir", args{"https://foo.com/bar/"}, []*http.Target{{IsTLS: true, Hostname: "foo.com", Port: 443, BasePath: "/bar/"}}, false},
{"full uri with port", args{"https://foo.com:8443"}, []*http.Target{{IsTLS: true, Hostname: "foo.com", Port: 8443}}, false},
{"full http with port", args{"http://foo.com:8080"}, []*http.Target{{IsTLS: false, Hostname: "foo.com", Port: 8080}}, false},
{"full http with port trailing slash", args{"http://foo.com:8080/"}, []*http.Target{{IsTLS: false, Hostname: "foo.com", Port: 8080, BasePath: "/"}}, false},
{"full http with port and path", args{"http://foo.com:8080/path"}, []*http.Target{{IsTLS: false, Hostname: "foo.com", Port: 8080, BasePath: "/path"}}, false},
{"host with port tls", args{"foo.com:8443"}, []*http.Target{{IsTLS: true, Hostname: "foo.com", Port: 8443}}, false},
{"host with port notls", args{"foo.com:8080"}, []*http.Target{{IsTLS: false, Hostname: "foo.com", Port: 8080}}, false},
Expand Down
21 changes: 19 additions & 2 deletions pkg/kiterunner/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,16 @@ func (r *Result) AppendPrettyBytes(b []byte) []byte {

// Append the path
b = r.Target.AppendBytes(b)
b = r.Route.AppendPath(b)

// avoid double appending a path where its not necessary
// this destroys branch prediction. which is annoying, but not sure where else we can handle this
// its a pretty unlikely case since its only hit when printing results
if b[len(b)-1] == '/' && len(r.Route.Path) > 0 && r.Route.Path[0] == '/' {
b = append(b, r.Route.Path[1:]...)
} else {
b = r.Route.AppendPath(b)
}

b = append(b, " "...)

b = appendColorEnd(b)
Expand Down Expand Up @@ -198,7 +207,15 @@ func (r *Result) AppendBytes(b []byte) []byte {

// Append the path
b = r.Target.AppendBytes(b)
b = r.Route.AppendPath(b)

// avoid double appending a path where its not necessary
// this destroys branch prediction. which is annoying, but not sure where else we can handle this
// its a pretty unlikely case since its only hit when printing results
if b[len(b)-1] == '/' && len(r.Route.Path) > 0 && r.Route.Path[0] == '/' {
b = append(b, r.Route.Path[1:]...)
} else {
b = r.Route.AppendPath(b)
}
b = append(b, " "...)

b = r.Response.AppendRedirectChain(b)
Expand Down

0 comments on commit 5c48bef

Please sign in to comment.