Skip to content

Commit

Permalink
Fix invalid JSON in /version endpoint response (#538)
Browse files Browse the repository at this point in the history
* Fix invalid JSON in /version endpoint response

* Fix test
  • Loading branch information
whatyouhide authored Oct 25, 2023
1 parent 3399ea0 commit c3d8bf6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func (server *ApiServer) Version(response http.ResponseWriter, request *http.Req
log := zerolog.Ctx(request.Context())

response.Header().Set("Content-Type", "application/json;charset=utf-8")
version := fmt.Sprintf(`{"version": "%s"}\n`, Version)
version := fmt.Sprintf("{\"version\": \"%s\"}\n", Version)
_, err := response.Write([]byte(version))
if err != nil {
log.Warn().Err(err).Msg("Version: Failed to write response to client")
Expand Down
2 changes: 1 addition & 1 deletion api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ func TestVersionEndpointReturnsVersion(t *testing.T) {
t.Fatal("Unable to read body from response")
}

if string(body) != `{"version": "git"}\n` {
if string(body) != "{\"version\": \"git\"}\n" {
t.Fatal("Expected to return Version from /version, got:", string(body))
}
})
Expand Down

0 comments on commit c3d8bf6

Please sign in to comment.