-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
FormatURLPath
helper to allow safer URL path building
Adds a helper to the top-level package called `FormatURLPath`. It's basically a pass-through to `Sprintf`, except that it only takes string parameters. This is designed to make invocations slightly more safe -- we've had a little trouble in the past where a string pointer was accidentally passed instead of a string, and because `Sprintf` doesn't automatically dereference or anything, the result is an invalid URL. It also gives us the opportunity to call `url.QueryEscape` on every parameter for a little additional safety. Previously, this was being invoked manually only in certain packages like `plan`. I changed all uses of `%v` in invocations to `%s` for consistency and because we won't need any types beyond strings. In the same spirit, I also changed all the places that we were concatenating strings (like `"/skus/"+id`) to invoke `FormatURLPath`. This patch is fairly noisy, but you can mostly just examine the added function in `stripe.go` and test in `stripe_test.go`: ``` go func FormatURLPath(format string, params ...string) string { // Parameters must be converted to interface{} before we send them to // Sprintf. untypedParams := make([]interface{}, len(params)) for i, param := range params { untypedParams[i] = interface{}(url.QueryEscape(param)) } return fmt.Sprintf(format, untypedParams...) } ```
- Loading branch information
Showing
43 changed files
with
151 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.