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

Add nosprintfhostport linter #2749

Merged
merged 3 commits into from
Apr 23, 2022
Merged

Add nosprintfhostport linter #2749

merged 3 commits into from
Apr 23, 2022

Commits on Apr 22, 2022

  1. Add gosprintfhostport linter

    The Go linter go-sprintf-host-port checks that sprintf is not used to
    construct a host:port combination in a URL. A frequent pattern is for a
    developer to construct a URL like this:
    
    ```go
    fmt.Sprintf("http://%s:%d/foo", host, port)
    ```
    
    However, if "host" is an IPv6 address like 2001:4860:4860::8888, the URL
    constructed will be invalid. IPv6 addresses must be bracketed, like
    this:
    
    ```
    http://[2001:4860:4860::8888]:9443
    ```
    
    The linter is naive, and really only looks for the most obvious cases,
    but where it's possible to infer that a URL is being constructed with
    Sprintf containing a :, this informs the user to use net.JoinHostPort
    instead.
    
    Running it against some real world code bases like OpenShift and
    Kubernetes has found a number of cases that would break in IPv6
    environments.
    stbenjam committed Apr 22, 2022
    Configuration menu
    Copy the full SHA
    eaa9d30 View commit details
    Browse the repository at this point in the history
  2. Fix items from checklist

    - Alphabetized manager.go
    - Added go glangci.example.yml
    - Used tag for go.mod
    stbenjam committed Apr 22, 2022
    Configuration menu
    Copy the full SHA
    6293bb4 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    a9b1541 View commit details
    Browse the repository at this point in the history