Browse Source

err on duplicated tag key

pull/7523/head
chrislu 2 weeks ago
parent
commit
eb054eb1f7
  1. 11
      weed/s3api/s3_metadata_util.go

11
weed/s3api/s3_metadata_util.go

@ -43,12 +43,17 @@ func ParseS3Metadata(r *http.Request, existing map[string][]byte, isReplace bool
glog.Warningf("Invalid S3 tag format in header '%s': %v", tags, err) glog.Warningf("Invalid S3 tag format in header '%s': %v", tags, err)
return nil, s3err.ErrInvalidTag return nil, s3err.ErrInvalidTag
} }
// Validate: S3 spec does not allow duplicate tag keys
for key, values := range parsedTags { for key, values := range parsedTags {
// According to S3 spec, if a key is provided multiple times, the last value is used.
// A tag value can be an empty string but not nil.
if len(values) > 1 {
glog.Warningf("Duplicate tag key '%s' in header '%s'", key, tags)
return nil, s3err.ErrInvalidTag
}
// Tag value can be an empty string but not nil
value := "" value := ""
if len(values) > 0 { if len(values) > 0 {
value = values[len(values)-1]
value = values[0]
} }
metadata[s3_constants.AmzObjectTagging+"-"+key] = []byte(value) metadata[s3_constants.AmzObjectTagging+"-"+key] = []byte(value)
} }

Loading…
Cancel
Save