From 5feac33f853440856108a2365881450a262234ac Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Mon, 7 Sep 2015 19:24:14 -0700 Subject: [PATCH] put yaml unmarshal after find/replace --- .../static/scripts/services/repos.js | 8 +++++++- pkg/server/repos.go | 18 +++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/cmd/drone-server/static/scripts/services/repos.js b/cmd/drone-server/static/scripts/services/repos.js index b58a5960a..c2fce6862 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 2c27c0125..b72b71b32 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 {