Skip to content

Commit

Permalink
[s3] Fix GetObjectTagging when there are no tags
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidZbarsky-at committed Jan 23, 2024
1 parent 1715371 commit 8b3c23b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
28 changes: 28 additions & 0 deletions services/s3/itest/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,34 @@ func TestObjectTagging(t *testing.T) {
}
}

func TestObjectTagging_NoTags(t *testing.T) {
ctx := context.Background()
client, srv := makeClientServerPair()
defer srv.Shutdown(ctx)

key := "test-key"
_, err := client.PutObject(ctx, &s3.PutObjectInput{
Bucket: &bucket,
Key: &key,
Body: strings.NewReader("hello"),
})
if err != nil {
t.Fatal(err)
}

tagging, err := client.GetObjectTagging(ctx, &s3.GetObjectTaggingInput{
Bucket: &bucket,
Key: &key,
})
if err != nil {
t.Fatal(err)
}
tags := tagging.TagSet
if len(tags) != 0 {
t.Fatal("bad tags", tagging.TagSet)
}
}

func TestBucketTagging(t *testing.T) {
ctx := context.Background()
client, srv := makeClientServerPair()
Expand Down
18 changes: 10 additions & 8 deletions services/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,17 @@ func (s *S3) GetObjectTagging(input GetObjectTaggingInput) (*GetObjectTaggingOut
}

tagging := &GetObjectTaggingOutput{}
for _, kv := range strings.Split(object.Tagging, "&") {
kv := strings.Split(kv, "=")
if len(kv) != 2 {
return nil, awserrors.XXX_TODO("invalid tagging")
if len(object.Tagging) > 0 {
for _, kv := range strings.Split(object.Tagging, "&") {
kvs := strings.Split(kv, "=")
if len(kvs) != 2 {
return nil, awserrors.XXX_TODO(fmt.Sprintf("invalid tagging: '%s', '%s'", kv, object.Tagging))
}
tagging.TagSet.Tag = append(tagging.TagSet.Tag, APITag{
Key: kvs[0],
Value: kvs[1],
})
}
tagging.TagSet.Tag = append(tagging.TagSet.Tag, APITag{
Key: kv[0],
Value: kv[1],
})
}
return tagging, nil
}
Expand Down

0 comments on commit 8b3c23b

Please sign in to comment.