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
provider/azure: strip off UTF-8 BOM from responses #6835
Conversation
QA add-credential azure, interactive, 10 times |
if _, err := io.Copy(&b, resp.Body); err != nil { | ||
return err | ||
} | ||
var decodeErr error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we're now reading the whole body, why not:
var utf8BOM = []byte("\ufeff") // global
data, err := ioutil.ReadAll(resp.Body)
if err != nil ...
if err := json.Unmarshal(bytes.TrimPrefix(data, utf8BOM), &oe); err != nil ... {
}
resp.Body = io.NopCloser(bytes.NewReader(data))
?
BTW I think it might be better to strip the BOM in all JSON decoding code - surely
this isn't the only place that can include it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW I think it might be better to strip the BOM in all JSON decoding code - surely
this isn't the only place that can include it?
Maybe, but we don't control the other code. That will need to go in go-autorest. The reason this code exists at all is because the AAD (Azure Active Directory) API endpoint is a little different to the other Azure API endpoints. Different error structures. So I wouldn't be surprised if this is the only place that the BOM shows up, because it's probably getting routed to a different backend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for the simplification: I'm intentionally preserving the behaviour of leaving the body as-is for the caller. But I think you're right, we should just chuck out the BOM and pretend it was never there. It's no use to anyone.
EDIT: and now I see yours preserves it too, I'm just a bit thick. I'll go with that.
LGTM with one thought, thanks. |
When handling responses from the AAD REST endpoint, strip off the UTF-8 BOM, if any, from JSON responses. These are only sometimes returned. Fixes https://bugs.launchpad.net/juju/+bug/1657448
59af41d
to
8a8592c
Compare
|
Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju |
When handling responses from the AAD REST endpoint,
strip off the UTF-8 BOM, if any, from JSON responses.
These are only sometimes returned.
Fixes https://bugs.launchpad.net/juju/+bug/1657448