-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(httpapi): don't return nil, nil with null JSON input
While working on ooni/probe#2396, I noticed that the httpapi code could return nil, nil when the input from the server was the `null` UTF-8 string. In such a case, golang translates the `null` string into a `nil` pointer. However, if we pass the pointer to a struct rather than the pointer to a pointer, the code returns an empty struct, which is much safer. This reasoning works as long as we assume the caller wants to get a struct by pointer or nil on error. If the caller for some reason wants the code to return a `**T` type, we're back in the case where the code can return `nil`, `nil`. But all our code always wants a `*T` back and this seems the only case that makes sense.
- Loading branch information
1 parent
a18c256
commit 4af1fbf
Showing
4 changed files
with
22 additions
and
7 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