From 6828cbdce1ebdb6dc5b87574ee8824dc8676fccb Mon Sep 17 00:00:00 2001 From: Anatoly Date: Thu, 30 Dec 2021 19:17:45 +0300 Subject: [PATCH] s3store: stricter character replacement regexp for x-amz-metadata (#598) * stricter character replacement rule for x-amz-metadata * misspell fixed --- pkg/s3store/s3store.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/s3store/s3store.go b/pkg/s3store/s3store.go index 5e864b9..32c910c 100644 --- a/pkg/s3store/s3store.go +++ b/pkg/s3store/s3store.go @@ -92,11 +92,9 @@ import ( "github.com/aws/aws-sdk-go/service/s3" ) -// This regular expression matches every character which is not defined in the -// ASCII tables which range from 00 to 7F, inclusive. -// It also matches the \r and \n characters which are not allowed in values -// for HTTP headers. -var nonASCIIRegexp = regexp.MustCompile(`([^\x00-\x7F]|[\r\n])`) +// This regular expression matches every character which is not +// considered valid into a header value according to RFC2616. +var nonPrintableRegexp = regexp.MustCompile(`[^\x09\x20-\x7E]`) // See the handler.DataStore interface for documentation about the different // methods. @@ -230,7 +228,7 @@ func (store S3Store) NewUpload(ctx context.Context, info handler.FileInfo) (hand for key, value := range info.MetaData { // Copying the value is required in order to prevent it from being // overwritten by the next iteration. - v := nonASCIIRegexp.ReplaceAllString(value, "?") + v := nonPrintableRegexp.ReplaceAllString(value, "?") metadata[key] = &v }