diff --git a/cmd/drone-server/static/scripts/services/repos.js b/cmd/drone-server/static/scripts/services/repos.js index b58a5960..c2fce686 100644 --- a/cmd/drone-server/static/scripts/services/repos.js +++ b/cmd/drone-server/static/scripts/services/repos.js @@ -80,7 +80,13 @@ * @param {string} Plaintext to encrypt. */ this.encrypt = function (repoName, plaintext) { - return $http.post('/api/repos/' + repoName + '/encrypt', btoa(plaintext)); + var conf = { + headers: { + 'Content-Type': 'text/plain; charset=UTF-8' + } + } + + return $http.post('/api/repos/' + repoName + '/encrypt', btoa(plaintext), conf); }; var callback, diff --git a/pkg/server/repos.go b/pkg/server/repos.go index 2c27c012..b72b71b3 100644 --- a/pkg/server/repos.go +++ b/pkg/server/repos.go @@ -254,7 +254,7 @@ func Encrypt(c *gin.Context) { repo := ToRepo(c) in, err := ioutil.ReadAll(c.Request.Body) if err != nil { - c.Fail(500, err) + c.Fail(400, err) return } in, err = base64.StdEncoding.DecodeString(string(in)) @@ -263,19 +263,19 @@ func Encrypt(c *gin.Context) { return } - // make sure the Yaml is valid format to prevent - // a malformed value from being used in the build - err = yaml.Unmarshal(in, &yaml.MapSlice{}) - if err != nil { - c.Fail(500, err) - return - } - // we found some strange characters included in // the yaml file when entered into a browser textarea. // these need to be removed in = bytes.Replace(in, []byte{'\xA0'}, []byte{' '}, -1) + // make sure the Yaml is valid format to prevent + // a malformed value from being used in the build + err = yaml.Unmarshal(in, &yaml.MapSlice{}) + if err != nil { + c.Fail(500, err) + return + } + // encrypts using go-jose out, err := secure.Encrypt(string(in), repo.Keys.Private) if err != nil {