You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to see encoding/json support email-style formatted base64 input. That is to say, I would like to see the following code not panic.
var data []byte = []byte(`
["VGhpcyBpcyBhIGxvbmcgdGV4dCBmaWxlLCBqdXN0IGZpbGxlZCBpbiB3aXRoIHJhbmRvbSB0ZXh0
IHRvIGZvcmNlIGxpbmUKd3JhcHBpbmcgb25jZSBpdCdzIEJhc2U2NC1lbmNvZGVkLgo="]
`)
func main() {
dec := make([]string,0)
err := json.Unmarshal(data, &dec)
if err != nil {
panic(err)
}
}
With the current implementation, however, it does panic:
panic: invalid character '\n' in string literal
Why? It would make it easier to write readable unit tests of code that does a lot of marshaling and unmarshaling of custom data types.
I can't imagine it would be especially expensive to support this feature always, as I imagine simply filtering out all whitespace from the input stream would do it. But if it did prove to be expensive, supporting it only optionally some how would be reasonable for me as well.
The text was updated successfully, but these errors were encountered:
Your input isn't valid JSON, though. As http://www.json.org/ says, strings cannot contain control characters -- and that's what the error message indicates.
mikioh
changed the title
Add support for line breaks for base64 input to json.Unmarshal()
encoding/json: Add support for line breaks for base64 input to json.Unmarshal()
Aug 3, 2017
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I would like to see
encoding/json
support email-style formatted base64 input. That is to say, I would like to see the following code not panic.With the current implementation, however, it does panic:
Why? It would make it easier to write readable unit tests of code that does a lot of marshaling and unmarshaling of custom data types.
I can't imagine it would be especially expensive to support this feature always, as I imagine simply filtering out all whitespace from the input stream would do it. But if it did prove to be expensive, supporting it only optionally some how would be reasonable for me as well.
The text was updated successfully, but these errors were encountered: