Skip to content

Commit

Permalink
Fix an edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
stbenjam committed Apr 6, 2022
1 parent e5f7683 commit 81a5890
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ func run(pass *analysis.Pass) (interface{}, error) {
fs := fsRaw.Value[1 : len(fsRaw.Value)-1]

regexes := []*regexp.Regexp{
// - Check to see if it looks like a URI with a port, basically scheme://%s:<something else>
// - Scheme, as per RFC3986 is ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
// - A format string substitution in the host portion
// These check to see if it looks like a URI with a port, basically scheme://%s:<something else>,
// or scheme://user:pass@%s:<something else>.
// Matching requirements:
// - Scheme as per RFC3986 is ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
// - A format string substitution in the host portion, preceded by an optional username/password@
// - A colon indicating a port will be specified
regexp.MustCompile(`[a-zA-Z0-9+-.]*://%s:.*`),

// Same as above, but allowing a username/password
regexp.MustCompile(`[a-zA-Z0-9+-.]*://[^/]*@%s:.*`),
regexp.MustCompile(`^[a-zA-Z0-9+-.]*://%s:[^@]*$`),
regexp.MustCompile(`^[a-zA-Z0-9+-.]*://[^/]*@%s:.*$`),
}

for _, re := range regexes {
Expand Down
2 changes: 2 additions & 0 deletions testdata/src/p/p.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
func _() {
_ = fmt.Sprintf("gopher://%s/foo", net.JoinHostPort("foo", "80"))

_ = fmt.Sprintf("postgres://%s:%[email protected]/%s", "foo", "bar", "baz")

_ = fmt.Sprintf("http://%s/foo", net.JoinHostPort("foo", "80"))

_ = fmt.Sprintf("telnet+ssl://%s/foo", net.JoinHostPort("foo", "80"))
Expand Down

0 comments on commit 81a5890

Please sign in to comment.