canonicalize ETag correctly (#7442)

Fixes #7441 
Trim extra quotes prefixing/suffixing ETag in
CompleteMultipartUpload request.
This commit is contained in:
poornas
2019-04-01 12:19:52 -07:00
committed by kannappanr
parent 619611933a
commit 023866642c
6 changed files with 69 additions and 5 deletions

View File

@@ -19,7 +19,7 @@ package cmd
import (
"context"
"net/http"
"strings"
"regexp"
"time"
"github.com/minio/minio/cmd/crypto"
@@ -27,6 +27,10 @@ import (
"github.com/minio/minio/pkg/handlers"
)
var (
etagRegex = regexp.MustCompile("\"*?([^\"]*?)\"*?$")
)
// Validates the preconditions for CopyObjectPart, returns true if CopyObjectPart
// operation should not proceed. Preconditions supported are:
// x-amz-copy-source-if-modified-since
@@ -230,8 +234,7 @@ func ifModifiedSince(objTime time.Time, givenTime time.Time) bool {
// canonicalizeETag returns ETag with leading and trailing double-quotes removed,
// if any present
func canonicalizeETag(etag string) string {
canonicalETag := strings.TrimPrefix(etag, "\"")
return strings.TrimSuffix(canonicalETag, "\"")
return etagRegex.ReplaceAllString(etag, "$1")
}
// isETagEqual return true if the canonical representations of two ETag strings