diff options
author | Chris Marchesi <chrism@vancluevertech.com> | 2018-08-21 22:24:41 -0700 |
---|---|---|
committer | Chris Marchesi <chrism@vancluevertech.com> | 2018-08-21 22:24:41 -0700 |
commit | 2c2b532a525ab2c05f6e9675efd529a052121713 (patch) | |
tree | c77ddbd5dd328b89670c3ad695fce7bc491b4879 /options.go | |
parent | 8c3c8b30b3394677d8eb16b159bfe9b4f61726a8 (diff) | |
download | go-git-2c2b532a525ab2c05f6e9675efd529a052121713.tar.gz |
git: Canonicalize incoming annotated tag messages
Tag messages are highly sensitive to being in the expected format,
especially when encoding/decoding for PGP verification.
As such, we do a simple trimming of whitespace on the incoming message
and add a newline on the end, to ensure there are no surprises here.
Signed-off-by: Chris Marchesi <chrism@vancluevertech.com>
Diffstat (limited to 'options.go')
-rw-r--r-- | options.go | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -3,6 +3,7 @@ package git import ( "errors" "regexp" + "strings" "golang.org/x/crypto/openpgp" "gopkg.in/src-d/go-git.v4/config" @@ -389,7 +390,9 @@ var ( type TagObjectOptions struct { // Tagger defines the signature of the tag creator. Tagger *object.Signature - // Message defines the annotation of the tag. + // Message defines the annotation of the tag. It is canonicalized during + // validation into the format expected by git - no leading whitespace and + // ending in a newline. Message string // TargetType is the object type of the target. The object specified by // Target must be of this type. @@ -409,6 +412,9 @@ func (o *TagObjectOptions) Validate(r *Repository, hash plumbing.Hash) error { return ErrMissingMessage } + // Canonicalize the message into the expected message format. + o.Message = strings.TrimSpace(o.Message) + "\n" + if o.TargetType == plumbing.InvalidObject || o.TargetType == plumbing.AnyObject { return ErrBadObjectType } |